//代码片段小解析~~
File f = new File(path);
File[] t = f.listFiles(); //这个方法来读取这个路径下的文件
import java.io.PrintWriter;
import java.io.FileReader;
import java.io.File;
class GetAllFileName{
public static void process(String path,String to){
File f=new File(path);
File list[] = f.listFiles();
StringBuffer sb=new StringBuffer();
for(int i=0;i<list.length;i++){
if(list[i].isFile()){
String temp = list[i].getName();
sb.append(temp);
sb.append('
');
}
}
try{
PrintWriter pw=new PrintWriter(to);
pw.write(sb.toString());
pw.close();
}
catch(Exception e){
e.printStackTrace();
}
}
public static void main(String []args)
String from="titles";
String to="titles.txt";
process(from,to);
}
}