1

When I'm running the following portion of code in Windows (in Linux I don't get this type of error), I get the java.io.IOException in the title. How can I resolve this issue? Thanks

    RandomAccessFile randomAccessFile = null;
    try {
        randomAccessFile = new RandomAccessFile(fileToAccess, "rw");
    } catch (FileNotFoundException e) {
        e.printStackTrace();
        System.exit(-1);
    }

    FileChannel outChannel = randomAccessFile.getChannel();


    try (outChannel; FileLock fileLock = outChannel.lock()) {

        FileManagement fileManagement = new FileManagement();

         Path path = Paths.get(fileToAccess);
         List<String> lines = Files.readAllLines(path, StandardCharsets.UTF_8);

        fileLock.release();

    } catch (OverlappingFileLockException | IOException ex) {
        System.err.println("Exception occured while trying to get a lock on File... " + ex.getMessage());
        System.exit(-1);
    }
  • Well, like it says, another process has part of the file locked. Why are you calling an input channel `outChannel`? – user207421 Oct 28 '19 at 02:33

0 Answers0