码迷,mamicode.com
首页 > 编程语言 > 详细

java创建和删除文件夹及文件

时间:2016-06-21 12:46:57      阅读:239      评论:0      收藏:0      [点我收藏+]

标签:

//新建一个文件夹
public void newFolder(String folderPath) {
try {
String filePath = folderPath;
File myFilePath = new File(filePath);
if (!myFilePath.exists()) {
myFilePath.mkdir();
}
} catch (Exception e) {
System.out.println("新建文件夹操作出错");
e.printStackTrace();
}
}
//删除文件夹
public void delFolder(String folderPath){
try{
String filePath = folderPath;
File delPath = new File(filePath);
delPath.delete();
}catch (Exception e) {
System.out.println("删除文件夹操作出错");
e.printStackTrace();
}
}
//新建文件
public void createFile(String fileName){
try{
String myFileName = fileName;
if (!myFileName.exists()) {
myFileName.createNewFile();
}
}catch (Exception e) {
System.out.println("新建文件操作出错");
e.printStackTrace();
}
}
//删除文件
public void delFile(String fileName){
try{
String myFileName = fileName;
myFileName.delete();
}catch (Exception e) {
System.out.println("删除文件操作出错");
e.printStackTrace();
}
}

java创建和删除文件夹及文件

标签:

原文地址:http://www.cnblogs.com/jzhxhs/p/5603117.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!