文件拒绝访问1
在写文件是报下面异常:
Exception in thread "main" java.io.FileNotFoundException: e:\a\b\a.txt (拒绝访问。)
at java.io.FileOutputStream.open(Native Method)
at java.io.FileOutputStream.<init>(Unknown Source)
at java.io.FileOutputStream.<init>(Unknown Source)
at cn.netjava.sample.CopyDirectory1.copyDirectory(CopyDirectory1.java:19)
原因在实例化File file=new File(fileAllName);的时候fileAllName是一个目录
而在下面这就就报上面的异常了。
FileWriter fw=new FileWriter(file);
解决办法,将fileAllName具体到文件名字。
文件拒绝访问2
复制文件时异常如下:
e:\a.txt是文件夹
Exception in thread "main" java.io.FileNotFoundException: e:\a.txt (拒绝访问。)
at java.io.FileOutputStream.open(Native Method)
原因:
文件不存在,因为有 file.mkdirs() 语句,文件转为文件夹
解脱方法:
if(!file.exists()){
file.createNewFile();
}
Could not find the main class. Program will exit
运行时出现如下错误:
Could not find the main class. Program will exit
原因:
运行环境不对
解决方法:
我把JRE System Library [jre1.6.0_04]改成JRE System Library[jre6]就对了
while的小错误
错误代码:
while(rs.next()){
Article art=new Article();
art.setId(rs.getInt("id"));
art.setId_user(rs.getInt("id_user"));
art.setName(rs.getString("name"));
list.add(art);
System.out.println("查找成功");
return list;
}
错误:
明明满足条件,却只循环一次
原因:
把return list 写在了循环里面
解决方法:
写到外面去