关于 createNewFile
import java.io.*;
public class Test_Create{
public static void main(String args[]){
File f1 = new File("d:/b/a/t.txt"); //如果这里使用 d:/t.txt 空文档就能创建出来。 是什么问题呢?我也测试了别的带参的createnewfile方法,还是没有理解。望指点迷津啊
if ( !f1.exists() ){
try {
System.out.println("文件不存在!创建该文件ing...");
f1.createNewFile();
System.out.println("创建成功!");
} catch (IOException e) {
e.printStackTrace();
}
}
if(f1.isDirectory()){
System.out.println("f1是目录 目录名:" + f1.getName());
System.out.println("路径名为:" + f1.getAbsolutePath());
} else if(f1.isFile()){
System.out.println("f1是文件 文件名:"+ f1.getName());
System.out.println("路径名为:" + f1.getAbsolutePath());
System.out.println("父路径为:" + f1.getParent());
} else {
System.out.println("抛出异常!");
}
}
}
/**
此程序编译是通过的,运行就会抛出异常。还没有把createNewFile()这个函数理解啊。
*/
高手们,帮忙看看。