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();
}
}
}
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();
}
}
}
相关文章推荐
- Java 判断文件夹、文件是否存在、否则创建文件夹
- Java创建文件夹并上传文件到该文件夹
- Java 创建文件夹和文件
- Java 判断文件夹、文件是否存在、否则创建文件夹
- java在不存在文件夹的目录下创建文件
- java在linux上创建文件/文件夹
- java 对文件的删除、剪切、移动和创建文件夹操作
- java nio: Files.isWritable判断文件夹可写(创建子文件夹或文件)
- Java创建、重命名、删除文件和文件夹
- Java 在给定路径上创建文件,所在文件夹不存在时,如何正确创建。
- java创建压缩文件方法(包括文件夹下包含文件夹)
- java File类创建文件夹与创建文件的区别
- Java创建文件和文件夹、文件属性的读取、文件属性的设置
- Java 判断文件夹、文件是否存在、否则创建文件夹
- JAVA FTP上只能创建文件夹,无法上传文件
- JAVA之旅(二十八)——File概述,创建,删除,判断文件存在,创建文件夹,判断是否为文件/文件夹,获取信息,文件列表,文件过滤
- JAVA之旅(二十八)——File概述,创建,删除,判断文件存在,创建文件夹,判断是否为文件/文件夹,获取信息,文件列表,文件过滤
- Java 判断文件夹、文件是否存在、否则创建文件夹
- JAVA 创建文件和文件夹,删除文件和文件夹的实用工具
- Java在linux上只能在程序的当前目录下创建文件/文件夹导致的问题