IO 判断文件夹或者文件是否存在 不存在创建一个

import java.io.File;
import java.io.IOException;

public class IO_Createfile {
    public static void main(String[] args) throws IOException{
        String strPath = "C:\\a\\aa\\aaa.txt";  
        File file = new File(strPath);  
        if(!file.getParentFile().exists()){//判断文件夹在不在  
              file.getParentFile().mkdirs();//文件夹不在 创建文件夹
          }if(!file.exists()){  //判断文件是否存在 不存在创建一个文件
            file.createNewFile();    
        }  
    }

}

 

posted on 2017-01-10 15:29  取个名字之麻烦  阅读(327)  评论(0)    收藏  举报