In my project, i need to imeplement file locking and the problem is that we need to use java 6 only so what are the ways through which i can implement file locking for both platform(windows/linux)
Asked
Active
Viewed 91 times
1 Answers
0
You can use nio API for that. Find the below code snippet. It will help you to solve your problem
FileInputStream in = new FileInputStream(file);
try {
java.nio.channels.FileLock lck = in.getChannel().lock();
try {
Reader reader = new InputStreamReader(in, charset);
...
} finally {
lck.release();
}
} finally {
in.close();
}
For more details you can refer java docs for FileLock https://docs.oracle.com/javase/8/docs/api/java/nio/channels/FileLock.html#pdep

Ankush
- 78
- 10