[ Does RandomAccessFile cause Lock? ]

This may appear a silly question, but I wanted to know if I opened a file using the RandomAccessFile implementation found within Java would cause an Access Violation if a program externally accessed or edited this file

Logic in my head dictated ‘NO’ it wouldn’t. So I put it too the test, attached below:

1RAF

Here I’m basically spawning a 4 threads to open a file and start getting information from the file.he Thread class implementation:2RAF.png

After running this, and even making an edit to the file via NOTEPAD, this is the result:

1RAF.png

As you can see now ACCESS VIOLATION within my PROGRAM, and even alterations outside the program do not affect the END RESULT, as all the above RandomAccessFile constructs were initialized at more or less similar moment in time, with a snapshot of the ‘textfile’, thus it does not reflect new changes I have made, since the ‘initialization’.

RandomAccessFile fileHandler = new RandomAccessFile(file, “r”);

Ok, enuff said!

Don't be shellfish...Share on FacebookShare on Google+Tweet about this on TwitterShare on LinkedInShare on TumblrEmail this to someone

Leave a Reply