Windows-Java Datei-Sperre, wenn vorhandene Datei im Konstruktor werben?
-
02-10-2019 - |
Frage
Angenommen, ich für einen Prozess des folgend in Java tun, dass Aufenthalte öffnen:
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());
}
}
}
Habe ich gesperrt diese Datei in einer Weise, dass andere Windows-Prozesse nicht in die Protokolldatei schreiben kann?
Lösung
This might help you : http://java.sun.com/j2se/1.4.2/docs/api/java/nio/channels/FileLock.html
Andere Tipps
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
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow