javawindowsconcurrencygarbage-collectionfilelock

Windows Java File lock when referencing existing file in constructor?


Suppose I do the following in java for a process that stays open:

import java.io.File;
import java.util.Date;
public class LogHolder {
    public static void main(String[] args) {
        File file1 = new File("myLogFile.log");        
        while (true) {
            System.out.println("Running " + new Date());
        }
    }
}

Have I locked this file in a way that other windows processes can't write to the log file?


Solution

  • This might help you: FileLock.