title: exception occurs when using MappedByteBuffer's READ_Write mode
body: <p>I want to test <code>MappedByteBuffer</code>'s  READ_WRITE mode. But I get an exception:</p>
  
  <pre><code>Exception in thread "main" java.nio.channels.NonWritableChannelException
   at sun.nio.ch.FileChannelImpl.map(FileChannelImpl.java:755)
   at test.main(test.java:13)
  </code></pre>
  
  <p>I have no idea have to fix it. 
  Thanks in advance.</p>
  
  <p><strong>now I fix the program and there is no exception. But the system returns a sequence of Garbage characters, but in fact there is just a string "asdfghjkl" in the file in.txt . I guess may be the coding scheme cause this problem, but i do not know how to verify it and fix it.</strong></p>
  
  <pre><code>import java.io.File;
  import java.nio.channels.*;
  import java.nio.MappedByteBuffer;
  import java.io.RandomAccessFile;
  
  class test{
      public static void main(String[] args) throws Exception{
  
      File f= new File("./in.txt");
      RandomAccessFile in = new RandomAccessFile(f, "rws");
      FileChannel fc = in.getChannel();
      MappedByteBuffer mbb = fc.map(FileChannel.MapMode.READ_WRITE, 0, f.length());
  
      while(mbb.hasRemaining())
          System.out.print(mbb.getChar());
      fc.close();
      in.close();
  
      }
  };
  </code></pre>