创建文件夹

来源:互联网 发布:opencv python 掩膜 编辑:程序博客网 时间:2024/05/14 16:59
import java.io.File;
import java.io.IOException;


public class Admin {


    public static void main(String... args) {
        String path0 = ".\\aa";
        String path1 = ".\\aakkk.java";


        File f = new File(path0);


        // 创建文件夹
        if (!f.exists()) {
            f.mkdirs();
        }


        f = new File(path1);


        // 创建文件
        if (!f.exists()) {
            try {
                f.createNewFile();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }

}



2:

import java.io.File ;
import java.io.IOException ;
public class FileDemo{
   public static void main(String args[]){
File f = new File(".\\"+File.separator+"photo") ;// 实例化File类的对象
f.mkdir() ; // 创建文件夹
System.out.println("创建成功");
}
};


原创粉丝点击