title: java.nio.file.NoSuchFileException: why nio not creating file
body: <p>I am using java.nio.file package and tried to create file with the following code. </p>
  
  <pre><code>private static void printReport(String filename, String str)throws Exception{
  
          ErrorCheck ec = new ErrorCheck();
          String fileName = "/var/Emails_log/"+filename;      
          Path filePath = Paths.get(fileName);
          File file = new File(fileName);             
          final BufferedWriter out = Files.newBufferedWriter(filePath, StandardCharsets.UTF_8, StandardOpenOption.APPEND);            
  
          try{                
              final Path tmp = filePath.getParent();
              if (tmp != null){ // null will be returned if the path has no parent
                      Files.createDirectories(tmp);   
              } else {
                  out.write(str);
                  out.write('\n');
              }               
          } catch(Exception e) {
              ec.errorMsg("ERROR: GSW.SendEmail.Exception =&gt;",e);
          } finally {
              if (out != null) {
                  out.flush();
                  out.close();
              }
          }           
      }
  </code></pre>
  
  <p>This throws following Exception:</p>
  
  <pre><code>java.nio.file.NoSuchFileException: /var/Emails_log/GSWvalidSentAddresses.txt
  at sun.nio.fs.UnixException.translateToIOException(UnixException.java:86)
  at sun.nio.fs.UnixException.rethrowAsIOException(UnixException.java:102)
  at sun.nio.fs.UnixException.rethrowAsIOException(UnixException.java:107)
  at sun.nio.fs.UnixFileSystemProvider.newByteChannel(UnixFileSystemProvider.java:214)
  at java.nio.file.spi.FileSystemProvider.newOutputStream(FileSystemProvider.java:430)
  at java.nio.file.Files.newOutputStream(Files.java:170)
  at java.nio.file.Files.newBufferedWriter(Files.java:2720)
  at SendEmail.printReport(SendEmail.java:114) SendEmail.send(SendEmail.java:87)
  </code></pre>
  
  <p>My question is why file is not created?</p>
  
  <p>Please advise</p>
  
  <p>Thanks in anticipation</p>