I want lock my input text file, in my program, so if the next occurrence of program is run on the same file it crash (throws exception). I know that i can lock file with "java.nio.channels.FileLock" but it's possible only if file is open for writing, and i open text file only for reading. I don't want use "RandomAccessFile" for reading file because is too slow and my file size is very big (10gb). Now i use this wy for reading my file:
FileInputStream fstream = new FileInputStream(this.inputFileName);
DataInputStream in = new DataInputStream(fstream);
BufferedReader br = new BufferedReader(new InputStreamReader(in));
I think this is fast way to read a text file. How can lock my text input file?