hawkeye
hawkeye

Reputation: 35732

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?

Upvotes: 1

Views: 464

Answers (2)

Inv3r53
Inv3r53

Reputation: 2959

This might help you: FileLock.

Upvotes: 1

jdigital
jdigital

Reputation: 12286

No, you haven't locked the file. Here's how the Java documentation summarizes the purpose of java.io.File:

An abstract representation of file and directory pathnames

(In other words, new File() doesn't even open the file.)

You can find the rest here: http://java.sun.com/javase/6/docs/api/java/io/File.html

Upvotes: 0

Related Questions