title: Converting a String to ByteBuffer
body: <p>I want to put a string into a <code>MappedByteBuffer</code> so I converted the string into a byte array first and put it into the buffer, but when I invoke the <code>.hasArray()</code> method it returns false, where is the problem ?</p>
  <p>Here is my code:</p>
  <pre><code>package server;
  
  import java.io.IOException;
  import java.nio.MappedByteBuffer;
  import java.nio.channels.FileChannel;
  import java.nio.charset.StandardCharsets;
  import java.nio.file.Path;
  import java.nio.file.Paths;
  import java.nio.file.StandardOpenOption;
  
  public class Server {
  
      public static void main(String[] args) throws IOException {
          Path path = Paths.get(&quot;F:\\Studying\\operating system\\OSTask1\\file.txt&quot;);
          FileChannel ch = FileChannel.open(path, StandardOpenOption.WRITE, StandardOpenOption.READ);
          MappedByteBuffer buf = ch.map(FileChannel.MapMode.READ_WRITE, 0, 4096);
          String s = &quot;hello world&quot;;
          byte[] arr = s.getBytes(StandardCharsets.UTF_8);
          buf.wrap(arr);
          System.out.println(buf.hasArray());
      }
      
  }
  </code></pre>