1 package shurushuchuliu; 2 import java.io.*; 3 public class Test2 { 4 5 public static void main(String[] args) { 6 // 操作目录 7 File ff=new File("d:/test1/test1.txt"); 8 if(!(ff.exists())) 9 { 10 if(ff.mkdirs()) 11 { 12 System.out.println("创建目录成功"); 13 } 14 else 15 { 16 System.out.println("创建目录失败"); 17 } 18 } 19 20 File f=new File("d:/test/test.txt"); 21 22 if(f.exists()) 23 { 24 System.out.println("创建文件成功"); 25 } 26 else 27 { 28 try { 29 f.createNewFile(); 30 } catch (IOException e) { 31 // TODO 自动生成的 catch 块 32 e.printStackTrace(); 33 } 34 } 35 36 } 37 38 }