为了账号安全,请及时绑定邮箱和手机立即绑定

编译不能通过,哪里的问题,和老师讲的代码一样。。。

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)

http://img1.sycdn.imooc.com//56bef92c00013afd05930685.jpg

正在回答

代码语言

1 回答

Test1 main 方法里加一句FileUtils fu = new FileUtils();

然后再用创造的实例调用方法 fu.listDirectory(new File("G:\\BaiduYunDownload"));

0 回复 有任何疑惑可以回复我~
#1

gao634209276 提问者

谢谢了,不是这个原因,listDirectory()是静态方法可以直接用类名调用。 我刚把这两个代码删了重新打了一遍。没有那个问题了,昨天不知道什么原因,可能加载错IllegalArgumentException了
2016-02-14 回复 有任何疑惑可以回复我~

举报

0/150
提交
取消

编译不能通过,哪里的问题,和老师讲的代码一样。。。

我要回答 关注问题
微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号