title: Java how to read from randomaccessfile into string?
body: <p>I have a randomaccess file that stores name, address, city, state, and zipcode. </p>
  
  <p>They are all a fixed size of bytes in the file (each entry). How would I read from the file into a string for each item like name, street, etc?</p>
  
  <p>I've tried </p>
  
  <pre><code> string name = raf.readUTF(); 
  </code></pre>
  
  <p>But I can't control how many bytes it reads will that stop it from working correctly? Or how does readUTF work exactly since no amount of total bytes to read can be supplied in the arguement?</p>
  
  <p>Or is a better approach to do </p>
  
  <pre><code> ENTRY1_SIZE = 32;
   raf.read(string1);
   raf.skipBytes(ENTRY1_SIZE - string1.size());
   raf.read(string2);
  </code></pre>
  
  <p>and so on like that. </p>
  
  <p>What would be the most efficient way to do this while still using a randomaccessfile?
  Basically I want to know how to read N bytes into a string that can be displayed in a textbox later.</p>
  
  <hr>
  
  <p>Response to the answer below. 
  I tried your method </p>
  
  <pre><code>        long position = 91;
          byte[] b = new byte[32];
          try{
          raf.seek(position);
          raf.readFully(b, position, 32);
          String name = (b, StandardCharsets.UTF_8);
  </code></pre>
  
  <p>But this error: The method readFully(byte[], int, int) in the type RandomAccessFile is not applicable for the arguments (byte[], long, int)</p>
  
  <p>What should be supplied for the middle argument? The current file pointer is a long so that wouldn't work either.</p>
  
  <p>Another error: StandardCharsets cannot be resolved or is not a field</p>