File
File的构造方法
java
public class dome {
public static void main(String[] args) {
File f1 = new File("D:\\Java\\hello");
System.out.println(f1);
File f2 = new File("D:","Java\\hello");
System.out.println(f2);
File f3 = new File("D:");
File f4 =new File(f3,"Java\\hello");
System.out.println(f4);
}
}
File创建功能
java
public class dome {
public static void main(String[] args) throws IOException {
//如果存在就flast,否则true
//创建文件
File f1 = new File("D:\\Java\\hello.txt");
System.out.println(f1.createNewFile());//不能与目录名相同
//创建目录
//如果存在就flast,否则true
File f2 = new File("D:\\Java\\JavaFile");
System.out.println(f1.mkdir());
System.out.println(f2.mkdirs());
}
}