Filed1=newFile("F:/JavaCode/hello1/hello.txt");Filed2=newFile("F:/JavaCode/hello1/hello.jar");try{d1.getParentFile().mkdirs();//创建目录d1.createNewFile();//创建文件d2.cr...
File d1=new File("F:/JavaCode/hello1/hello.txt");
File d2=new File("F:/JavaCode/hello1/hello.jar");
try {
d1.getParentFile().mkdirs();//创建目录
d1.createNewFile();//创建文件
d2.createNewFile();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
System.out.println(d1+(d1.canRead()?" can ":" can not ")+" read .");
System.out.println(d1+(d1.canWrite()?" can ":" can not ")+" write .");
System.out.println(d1+(d2.canRead()?" can ":" can not ")+" read .");
System.out.println(d1+(d2.canWrite()?" can ":" can not ")+" write .");
}
结果都是
F:\JavaCode\hello1\hello.txt can read .
F:\JavaCode\hello1\hello.txt can write .
F:\JavaCode\hello1\hello.txt can read .
F:\JavaCode\hello1\hello.txt can write .
展开