gao634209276
2016-02-13 17:36
package com.imooc.io;
import java.io.File;
import java.io.IOException;
//列出File的一些常用的比如过滤,遍历等操作
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)

Test1 main 方法里加一句FileUtils fu = new FileUtils();
然后再用创造的实例调用方法 fu.listDirectory(new File("G:\\BaiduYunDownload"));
文件传输基础——Java IO流
133857 学习 · 1060 问题
相似问题