欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

java文件操作報(bào)錯(cuò):java.io.FileNotFoundException(拒絕訪問)問題

 更新時(shí)間:2024年10月04日 10:04:47   作者:java全套學(xué)習(xí)資料  
在進(jìn)行編程時(shí),經(jīng)常會遇到因疏忽小細(xì)節(jié)而導(dǎo)致的錯(cuò)誤,如忘記在路徑后添加文件名,本文通過一個(gè)具體的修改前后對比示例,解釋了錯(cuò)誤原因,并給出了解決方案,這類經(jīng)驗(yàn)分享對編程學(xué)習(xí)者具有參考價(jià)值

java文件操作報(bào)錯(cuò):java.io.FileNotFoundException(拒絕訪問)

錯(cuò)誤信息

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)

代碼

1)修改前:

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

		File source = new File("d:\aa\aa.txt"); // 源目標(biāo)路徑
		File dest = new File("e:\bb\"); // 目標(biāo)路徑

		copyFile(source, dest);

	}

2)修改后:

錯(cuò)誤的原因是讀取的目錄后面忘加了文件名!

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

		File source = new File("d:\aa\aa.txt"); // 源目標(biāo)路徑
		File dest = new File("e:\bb\" + source.getName()); // 目標(biāo)路徑

		copyFile(source, dest);

	}

總結(jié)

以上為個(gè)人經(jīng)驗(yàn),希望能給大家一個(gè)參考,也希望大家多多支持腳本之家。

相關(guān)文章

最新評論