话不多说,眼见为实,有多少人知道这个坑?!
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
public class FileTest {
public static void deleteFile() throws IOException {
File f=new File("D:\\rubbish\\new.png");// mac下换其他文件名
FileOutputStream ou=new FileOutputStream(f);// 打开文件流,不关闭
System.out.println(f.delete());// 打印true或者false
}
public static void main(String[] args) throws IOException {
deleteFile();
}
}
重点来了,windows输出false,而其他平台却是true!!!!
虽说java跨平台,但是不同平台表现还是有差距的,尤其对文件的操作!!!