您的位置:首页 > 编程语言 > Java开发

java 创建文件夹和文件

2011-05-08 12:20 330 查看
import java.io.*;

public class Fan {

public static void main(String[] args) {

String path ="d://upload_test//file"; //设置一个默认文件夹路径
File uploadFilePath = new File(path);

// 如果该目录不存在,则创建之
if(uploadFilePath.exists() == false) {
uploadFilePath.mkdirs();
System.out.println("路径不存在,但是已经成功创建了" + path);
}else{
System.out.println("文件路径存在" + path);
}

String filePath = path+"//xin.txt";
File createFile = new File(filePath);
try {
createFile.createNewFile();
System.out.println("文件创建成功!");
} catch (IOException e) {
System.out.println("文件创建失败了!");
e.printStackTrace();
}

}

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: