完美解决JavaIO流报错 java.io.FileNotFoundException: F:\ (系统找不到指定的路径。)
完美解决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();
}
}
}
}
完美解决JavaIO流报错 java.io.FileNotFoundException: F:\ (系统找不到指定的路径。)的更多相关文章
- python setup.py install 报错:error: [WinError 3] 系统找不到指定的路径。: 'C:\\Program Files (x86)\\Microsoft Visual Studio 14.0\\VC\\PlatformSDK\\lib
Outline 在通过 setup.py 安装python模块时,遇到了以下报错: # 执行 python setup.py install # 报错: error: [WinError 3] 系统找 ...
- 解决 mysql 启动报错--发现系统错误2,系统找不到指定的文件
HKEY_LOCAL_MACHINE-SYSTEM-CurrentControlSet-services-mysql(服务名)-ImagePath 更改为(自己的):"C:\Program ...
- 关于SpringMVC项目报错:java.io.FileNotFoundException: Could not open ServletContext resource [/WEB-INF/xxxx.xml]
关于SpringMVC项目报错:java.io.FileNotFoundException: Could not open ServletContext resource [/WEB-INF/xxxx ...
- 文件上传报错java.io.FileNotFoundException拒绝访问
局部代码如下: File tempFile = new File("G:/tempfileDir"+"/"+fileName); if(!tempFile.ex ...
- 关于spark入门报错 java.io.FileNotFoundException: File file:/home/dummy/spark_log/file1.txt does not exist
不想看废话的可以直接拉到最底看总结 废话开始: master: master主机存在文件,却报 执行spark-shell语句: ./spark-shell --master spark://ma ...
- Spark启动报错|java.io.FileNotFoundException: File does not exist: hdfs://hadoop101:9000/directory
at org.apache.spark.deploy.history.FsHistoryProvider.<init>(FsHistoryProvider.scala:) at org.a ...
- Java properties | FileNotFoundException: properties (系统找不到指定的文件。)
文件存储路径的问题 错误描述 :FileNotFoundException: init.properties (系统找不到指定的文件.) 1.方法一 InputStream fis =TestProp ...
- 转:Java properties | FileNotFoundException: properties (系统找不到指定的文件。)
原文地址:https://blog.csdn.net/cor_twi/article/details/44514871 web项目 (dynamic web project ) 读取propertie ...
- mysql 启动报错--发现系统错误2,系统找不到指定的文件。
解决方法: 控制面板--找到mysql程序--修复
随机推荐
- taro小程序地址选择组件
效果图: address_picker.tsx: import Taro, { Component } from '@tarojs/taro' import { View, PickerView, P ...
- SpringCloud升级之路2020.0.x版-23.订制Spring Cloud LoadBalancer
本系列代码地址:https://github.com/HashZhang/spring-cloud-scaffold/tree/master/spring-cloud-iiford 我们使用 Spri ...
- 映射Map、队列Queue、优先级队列PriorityQueue
映射Map 将对象映射到其他对象的能力是解决编程问题的有效方法.例如,考虑一个程序,它被用来检查 Java 的 Random 类的随机性.理想情况下, Random 会产生完美的数字分布,但为了测试这 ...
- 【SpringMVC】域对象共享数据
使用ModelAndView向request域对象共享数据 index.html <a th:href="@{/testModelAndView}">使用ModelAn ...
- Docker与数据:三种挂载方式
操作系统与存储 操作系统中将存储定义为 Volume(卷) ,这是对物理存储的逻辑抽象,以达到对物理存储提供有弹性的分割方式.另外,将外部存储关联到操作系统的动作定义为 Mount(挂载). Dock ...
- github push报LibreSSL SSL_connect错误
最近发现在家里push代码到github的时候总是报错,报错内容如下: fatal: unable to access 'https://github.com/MangoDowner/clear-le ...
- ES6中class的继承
extends 子类的继承 super(); 调用父类的构造方法,只能在子类中执行 继承可以让子类获得父类的方法 属性,可以扩充 增加新的方法 属性等 父类(基类)--被继承的类 子类--继承后的类 ...
- dotnet OpenXML 读取 PPT 内嵌 ole 格式 Excel 表格的信息
在 Office 中,可以在 PPT 里面插入表格,插入表格有好多不同的方法,对应 OpenXML 文档存储的更多不同的方式.本文来介绍如何读取 PPT 内嵌 ole 格式的 xls+ 表格的方法 在 ...
- Python语法之选择和循环(if、while)
前言:在程序开发中,一共有三种流程方式: 顺序:从上向下,顺序执行代码 分支:根据条件判断,决定执行代码的分支 循环:让特定代码重复执行(解决程序员重复工作) 1.判断的定义: 如果条件满足,才能做某 ...
- 如何获取 Android CPU 核心数 (Java/C++)
1 前言 最近学习Power HAL方面相关知识,透过Power HAL 去配置CPU的Freq需要先确定 CPU 核数.便先了解如何获取 Android CPU 核数. 2 Java层获取方式 // ...