01-错误信息:

Exception in thread "main" java.io.FileNotFoundException: e:b (拒绝访问。)
	at java.io.FileOutputStream.open0(Native Method)
	at java.io.FileOutputStream.open(Unknown Source)
	at java.io.FileOutputStream.<init>(Unknown Source)
	at java.io.FileOutputStream.<init>(Unknown Source)
	at com.eleven.SevenDemo04.copyFile(SevenDemo04.java:44)
	at com.eleven.SevenDemo04.main(SevenDemo04.java:21)

02-代码:

1)修改前:

public static void main(String[] args) throws Exception {

		File source = new File("d:\aa\aa.txt"); // 源目标路径
		File dest = new File("e:\bb\"); // 目标路径

		copyFile(source, dest);

	}

2)修改后:

错误的原因是读取的目录后面忘加了文件名!

public static void main(String[] args) throws Exception {

		File source = new File("d:\aa\aa.txt"); // 源目标路径
		File dest = new File("e:\bb\" + source.getName()); // 目标路径

		copyFile(source, dest);

	}

更多推荐

(完美解决)java文件操作报错:java.io.FileNotFoundException(拒绝访问)