分类: Java

 

1、判断文件是否存在,不存在创建文件

 

  1. File file=new File("C:\\Users\\QPING\\Desktop\\JavaScript\\2.htm");    
  2. if(!file.exists())    
  3. {    
  4.     try {    
  5.         file.createNewFile();    
  6.     } catch (IOException e) {    
  7.         // TODO Auto-generated catch block    
  8.         e.printStackTrace();    
  9.     }    
  10. }    


 

2、判断文件夹是否存在,不存在创建文件夹

 

  1. File file =new File("C:\\Users\\QPING\\Desktop\\JavaScript");    
  2. //如果文件夹不存在则创建    
  3. if  (!file .exists()  && !file .isDirectory())      
  4. {       
  5.     System.out.println("//不存在");  
  6.     file .mkdir();    
  7. else   
  8. {  
  9.     System.out.println("//目录存在");  
  10. }
  11. http://blog.chinaunix.net/uid-26284395-id-3260936.html  

相关文章:

  • 2021-06-11
  • 2022-12-23
  • 2022-12-23
  • 2021-11-04
  • 2022-01-22
  • 2021-11-03
猜你喜欢
  • 2022-12-23
  • 2021-08-09
  • 2022-12-23
  • 2022-12-23
  • 2021-12-23
  • 2021-10-29
相关资源
相似解决方案