title: How the RandomAccessFile class returns bytes with randomAccessFile.read() method;
body: <p>I'm using the google translator , I hope the question is well understood.</p>
  
  <p>There is one thing I do not understand the random access files .No understand how the program works but it works.</p>
  
  <p>This is my program :</p>
  
  <pre><code>// ---------------------------------------------
  RandomAccessFile RandomAccessFile = new RandomAccessFile ( " pathfile ", " r");
  
  byte [] document = new byte [ ( int) randomAccessFile.length ()] ;
  
  randomAccessFile.read (document) ;
  // ---------------------------------------------
  </code></pre>
  
  <p>In line 1 I access the file in read
  In line 2 I create a byte array object the same size as the file
  In line 3 reads the array of bytes</p>
  
  <p>But never the file on the array of bytes is dumped .</p>
  
  <p>I think the program should look something like :</p>
  
  <pre><code>/ / ---------------------------------------------
  RandomAccessFile RandomAccessFile = new RandomAccessFile ( " pathfile ", " r");
  
  byte [] document = new byte [ ( int) randomAccessFile.length ()] ;
  
  // Line changed
  document = randomAccessFile.read();
  // ---------------------------------------------
  </code></pre>
  
  <p>The java documentation says :</p>
  
  <pre><code>randomAccessFile.read() ;
  
  Reads a byte of data from this file . The byte is returned as an integer in
  the range 0 to 255 ( 0x00- 0x0ff ) .
  </code></pre>
  
  <p>Only returns the number of bytes but not bytes.</p>
  
  <p>Someone could explain to me how this line dumps the bytes in the byte [] variable document with this statement ?</p>
  
  <pre><code>randomAccessFile.read (document) ;
  </code></pre>
  
  <p>Thanks!!</p>
  
  <p>// ------------------------------------------------------------------------------</p>
  
  <p>Another example:</p>
  
  <p>I compare this method with BufferedReader: </p>
  
  <pre><code>File file = new File ("C: \ \ file.txt"); 
  FileReader fr = new FileReader (file); 
  BufferedReader br = new BufferedReader (fr); 
  ... 
  String line = br.readLine (); 
  </code></pre>
  
  <p>BufferedReader reads a line and passes it to a string. </p>
  
  <p>I can see with this java statement that passes the file contents to a variable. </p>
  
  <pre><code>String line = br.readLine ();
  </code></pre>
  
  <p>But I do not see that with this other statement: </p>
  
  <pre><code>RandomAccessFile.read ();
  </code></pre>
  
  <p>just read, the content does not pass that line anywhere ... </p>