我想把以下代码的查询结果和过程存到一个文本里
/**
*查看文件数量
*/
import java.lang.*;
import java.io.*;
public class Test{
static int tot;
public static void main(String []args){
Test fileTest = new Test();
try{
String path = args[0];
File file = new File(path);
fileTest.doDir(file);
String total = "文件数是 : "+tot;
System.out.println(total);
}catch(Exception err){
}
}
public void doDir (File file){
try{
File []files = file.listFiles();
for(int i=0; i <files.length;i++){
if(files[i].isDirectory()){
doDir(files[i]);
}else{
doFile(files[i]);
tot++;
}
}
}catch(Exception error){
}
}
public void doFile(File file){
String path = file.getPath();
System.out.println(path);
}
}
用代码实现
------解决方案--------------------JAVA IO
FileWriter writer=new FileWriter( "Data.txt ");
writer.write(data,0,data.length);
------解决方案--------------------加writer.flush();
------解决方案--------------------FileWriter writer=new FileWriter( "Data.txt ",true);
试试。最好加缓冲
------解决方案--------------------writer.write(files,0,files.length);中的write方法错误,中的file类型错误