Advertisement
Guest User

Untitled

a guest
Jun 25th, 2019
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.80 KB | None | 0 0
  1. if (!file.exists() && !file.createNewFile()) {
  2. System.err.println("Error with output file: " + outFile
  3. + "nCannot create new file.");
  4. continue;
  5. }
  6.  
  7. file.getParentFile().mkdirs()
  8.  
  9. try {
  10. if(!file.createNewFile()) {
  11. System.out.println("File already exists");
  12. }
  13. } catch (IOException ex) {
  14. System.out.println(ex);
  15. }
  16.  
  17. if (file.getParentFile() != null && !file.getParentFile().mkDirs()) {
  18. // handle permission problems here
  19. }
  20. // either no parent directories there or we have created missing directories
  21. if (file.createNewFile() || file.isFile()) {
  22. // ready to write your content
  23. } else {
  24. // handle directory here
  25. }
  26.  
  27. if (file.exists() && !file.isFile()){
  28. //handle directory is there
  29. }else if(!file.createNewFile()) {
  30. //as before
  31. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement