首先,一个简单的测试代码:
package javaapplication23;
import java.io.IOException;
import java.util.logging.FileHandler;
public class JavaApplication23 {
public static void main(String[] args) throws IOException {
new FileHandler("./test_%u_%g.log", 10000, 100, true);
}
}
Run Code Online (Sandbox Code Playgroud)
此测试代码仅使用Java 7创建一个文件"test_0_0.log",无论我多久运行一次该程序.这是预期的行为,因为构造函数中的append参数设置为true.
但是如果我在Java 8中运行此示例,则每次运行都会创建一个新文件(test_0_0.log,test_0_1.log,test_0_2.log,...).我认为这是一个错误.
Imho,Java的相关变化是这样的:
@@ -413,18 +428,18 @@
// object. Try again.
continue;
}
- FileChannel fc;
+
try {
- lockStream = new FileOutputStream(lockFileName);
- fc = lockStream.getChannel();
- } catch (IOException ix) {
- // We got an IOException while trying to open the file.
- // Try the next file. …Run Code Online (Sandbox Code Playgroud)