FileOutputStream fileOutputStream = new FileOutputStream(myFile);
FileChannel channel = fileOutputStream.getChannel();
FileLock lock = channel.tryLock(); // specifically not using lock,
FileInputStream fileInputStream = new FileInputStream(myFile);
BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(fileInputStream));
while ((line = bufferedReader.readLine()) != null) {}
java.nio.channels.OverlappingFileLockException
的结果我认为这会起作用,因为两个流都在同一个线程/进程中。但是锁似乎是基于流应用的?