java文件操作

import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;

public class Create {
public void createFloader(){
File myfloader;
File tempfloader;
boolean flag;
String filename;
try{
myfloader = new File("C://test");
flag = myfloader.exists();
if(flag){
System.out.println("文件夹已存在!");
}
else{
System.out.println("开始创建文件夹...");
flag = myfloader.mkdir();
if(flag){
System.out.println("文件夹创建成功...");
}
else{
System.out.println("文件夹创建失败...");
System.exit(1);
}
}

for(int i=0;i<5;i++){
filename = new String("C://test//");
filename += String.valueOf(i);
tempfloader = new File(filename + ".txt");
flag = tempfloader.createNewFile();
}

}
catch(Exception e){
e.printStackTrace();
}
}

public static void main(String arg[]){
Create cf = new Create();
cf.createFloader();
}

publicvoidremoveFile(Stringpath){
this.removeFile(newFile(path));
}


publicvoidremoveFile(Filepath){
System.out.println(
"removingfile"+path.getPath());
if(path.isDirectory()){
File[]child
=path.listFiles();
if(child!=null&&child.length!=0){
for(inti=0;i<child.length;i++){
removeFile(child[i]);
child[i].delete();
}

}

}

path.delete();
}

}

你可能感兴趣的:(java)