title: I'm Confused with Java NIO
body: <p>I'm confused with java nio buffers and <code>Files.write</code> if I can write with buffers and channels on file why do I need Files class.</p>
  
  <p>What's difference between both of these working code examples.</p>
  
  <pre><code>String newData = "New String to write to file..." + System.currentTimeMillis();
  
  Path path = Paths.get("C://data/nio-data2.txt");
  try {
      Files.write(path,newData.getBytes());
  } catch (IOException e) {
      e.printStackTrace();
  }
  </code></pre>
  
  <p>and</p>
  
  <pre><code>try {
      RandomAccessFile aFile = new RandomAccessFile("C://data/nio-data.txt", "rw");
      FileChannel channel = aFile.getChannel();
      ByteBuffer buf = ByteBuffer.allocate(48);
      buf.clear();
      buf.put(newData.getBytes());
  
      buf.flip();
  
      while(buf.hasRemaining()) {
          channel.write(buf);
      }
  } catch (FileNotFoundException e) {
      e.printStackTrace();
  } catch (IOException e) {
      e.printStackTrace();
  }
  </code></pre>
  
  <p>EDIT</p>
  
  <p>i want to ask one more question, is Channels.newOutputStream interrupt the thread when write to file or worked as a non-blocking</p>