I'm using the google translator , I hope the question is well understood.
There is one thing I do not understand the random access files .No understand how the program works but it works.
This is my program :
// ---------------------------------------------
RandomAccessFile RandomAccessFile = new RandomAccessFile ( " pathfile ", " r");
byte [] document = new byte [ ( int) randomAccessFile.length ()] ;
randomAccessFile.read (document) ;
// ---------------------------------------------
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
But never the file on the array of bytes is dumped .
I think the program should look something like :
/ / ---------------------------------------------
RandomAccessFile RandomAccessFile = new RandomAccessFile ( " pathfile ", " r");
byte [] document = new byte [ ( int) randomAccessFile.length ()] ;
// Line changed
document = randomAccessFile.read();
// ---------------------------------------------
The java documentation says :
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 ) .
Only returns the number of bytes but not bytes.
Someone could explain to me how this line dumps the bytes in the byte [] variable document with this statement ?
randomAccessFile.read (document) ;
Thanks!!
// ------------------------------------------------------------------------------
Another example:
I compare this method with BufferedReader:
File file = new File ("C: \ \ file.txt");
FileReader fr = new FileReader (file);
BufferedReader br = new BufferedReader (fr);
...
String line = br.readLine ();
BufferedReader reads a line and passes it to a string.
I can see with this java statement that passes the file contents to a variable.
String line = br.readLine ();
But I do not see that with this other statement:
RandomAccessFile.read ();
just read, the content does not pass that line anywhere ...