测试类FileNullBytes.java
:
package com.anbai.sec.filesystem;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
/**
* @author yz
*/
public class FileNullBytes {
public static void main(String[] args) {
try {
String fileName = "/tmp/null-bytes.txt\u0000.jpg";
FileOutputStream fos = new FileOutputStream(new File(fileName));
fos.write("Test".getBytes());
fos.flush();
fos.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
使用JDK1.7.0.25
测试成功截断文件名:
使用JDK1.7.0.80
测试写文件截断时抛出java.io.FileNotFoundException: Invalid file path
异常: