package?com.imooc.io;
import?java.io.File;
import?java.io.IOException;
//列出File的一些常用的比如過(guò)濾,遍歷等操作
public?class?FileUtils?{
/**
?*?列出指定目錄下(包括其子目錄)的所有文件
?*/
public?static?void?listDirectory(File?dir)throws?IOException(){
if(!dir.exists()){
throw?new?IllegalArgumentException("目錄:"+dir+"不存在");
}
if(!dir.isDirectory()){
throw?new?IllegalArgumentException(dir+"不是目錄");
}
String[]?filenames?=?dir.list();
for?(String?string?:?filenames)?{
System.out.println(string);
}
}
}
package?com.imooc.io;
import?java.io.File;
import?java.io.IOException;
public?class?Test1?{
public?static?void?main(String[]?args)?throws?IOException?{
//?TODO?Auto-generated?method?stub
FileUtils.listDirectory(new?File("G:\\BaiduYunDownload"));
}
}
Exception?in?thread?"main"?java.lang.Error:?Unresolved?compilation?problems:?
Syntax?error?on?token?"throws",?@?expected?after?this?token
Syntax?error,?insert?"SimpleName"?to?complete?ClassType
Syntax?error?on?token?"}",?delete?this?token
at?com.imooc.io.FileUtils.listDirectory(FileUtils.java:13)
at?com.imooc.io.Test1.main(Test1.java:10)

2016-02-14
Test1 main 方法里加一句FileUtils fu = new FileUtils();
然后再用創(chuàng)造的實(shí)例調(diào)用方法 fu.listDirectory(new?File("G:\\BaiduYunDownload"));