完美解决JavaIO流报错 java.io.FileNotFoundException: F:\ (系统找不到指定的路径。)
2021-06-08 12:05
标签:系统 pypi des load puts file ace ase png 读出文件的路径需要有被拷贝的文件名,否则无法解析地址 完美解决JavaIO流报错 java.io.FileNotFoundException: F:\ (系统找不到指定的路径。) 标签:系统 pypi des load puts file ace ase png 原文地址:https://www.cnblogs.com/Neroblogs/p/14524320.html完美解决JavaIO流报错 java.io.FileNotFoundException: F:\ (系统找不到指定的路径。)
错误原因
源代码(用于拷贝)
package com.javase.IO.Stream;
import org.junit.Test;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
public class CopyPicture {
@Test
public void copy(){
File srcFile = new File("D:\\test.jpg");
File destFile = new File("F:\\");
FileInputStream fis = null;
FileOutputStream fos = null;
try {
fis = new FileInputStream(srcFile);
fos = new FileOutputStream(destFile);
byte[] bytes = new byte[1024 * 1024];
int len = 0;
while((len = fis.read(bytes)) != -1){
fos.write(bytes,0,len);
}
fos.flush();
} catch (IOException e) {
e.printStackTrace();
} finally {
try {
if (fis != null) {
fis.close();
}
} catch (IOException e) {
e.printStackTrace();
}
try {
if (fos != null) {
fos.close();
}
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
修改后的代码
package com.javase.IO.Stream;
import org.junit.Test;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
public class CopyPicture {
@Test
public void copy(){
File srcFile = new File("D:\\test.jpg");
File destFile = new File("F:\\test.jpg");
FileInputStream fis = null;
FileOutputStream fos = null;
try {
fis = new FileInputStream(srcFile);
fos = new FileOutputStream(destFile);
byte[] bytes = new byte[1024 * 1024];
int len = 0;
while((len = fis.read(bytes)) != -1){
fos.write(bytes,0,len);
}
fos.flush();
} catch (IOException e) {
e.printStackTrace();
} finally {
try {
if (fis != null) {
fis.close();
}
} catch (IOException e) {
e.printStackTrace();
}
try {
if (fos != null) {
fos.close();
}
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
上一篇:spring_mvc执行原理
下一篇:PHP日期和函数
文章标题:完美解决JavaIO流报错 java.io.FileNotFoundException: F:\ (系统找不到指定的路径。)
文章链接:http://soscw.com/index.php/essay/92211.html