//新建一个文件夹
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();
}
}

相关文章:

  • 2022-12-23
  • 2021-10-04
  • 2021-10-31
  • 2022-12-23
  • 2021-11-04
  • 2022-03-02
  • 2021-12-26
猜你喜欢
  • 2022-12-23
  • 2021-12-03
  • 2021-11-18
  • 2021-12-26
  • 2022-12-23
  • 2021-10-12
相关资源
相似解决方案