完美解决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:\ (系统找不到指定的路径。)的更多相关文章

  1. 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] 系统找 ...

  2. 解决 mysql 启动报错--发现系统错误2,系统找不到指定的文件

    HKEY_LOCAL_MACHINE-SYSTEM-CurrentControlSet-services-mysql(服务名)-ImagePath 更改为(自己的):"C:\Program ...

  3. 关于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 ...

  4. 文件上传报错java.io.FileNotFoundException拒绝访问

    局部代码如下: File tempFile = new File("G:/tempfileDir"+"/"+fileName); if(!tempFile.ex ...

  5. 关于spark入门报错 java.io.FileNotFoundException: File file:/home/dummy/spark_log/file1.txt does not exist

    不想看废话的可以直接拉到最底看总结 废话开始: master: master主机存在文件,却报 执行spark-shell语句:  ./spark-shell  --master spark://ma ...

  6. 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 ...

  7. Java properties | FileNotFoundException: properties (系统找不到指定的文件。)

    文件存储路径的问题 错误描述 :FileNotFoundException: init.properties (系统找不到指定的文件.) 1.方法一 InputStream fis =TestProp ...

  8. 转:Java properties | FileNotFoundException: properties (系统找不到指定的文件。)

    原文地址:https://blog.csdn.net/cor_twi/article/details/44514871 web项目 (dynamic web project ) 读取propertie ...

  9. mysql 启动报错--发现系统错误2,系统找不到指定的文件。

    解决方法: 控制面板--找到mysql程序--修复

随机推荐

  1. Walkthrough: Create and use your own Dynamic Link Library (C++)

    参考网站:https://docs.microsoft.com/en-us/cpp/build/walkthrough-creating-and-using-a-dynamic-link-librar ...

  2. PL/SQL 安装使用

    PL/SQL 安装 前提:安装Oracle 使用 登录 oracle连接地址格式 ip:端口/ServerName,如192.168.136.130:1521/xe 新建菜单 Sql-Window 编 ...

  3. c# 对 struct为什么不能继承类和结构的思考

    1.类.结构在使用的时候可以不调用构造函数,如果能够继承类,这种情况下不能够初始化基类,因为不执行构造函数 2.结构.所有的结构类型都默认是 sealed,通过 反汇编可以看到  ,这就阻止了结构被继 ...

  4. nodejs根据word模板生成文档(方法二)

    [推荐该方法,模板比较简洁] 1,代码, 这里采用的模块为 docxtemplater 和 open-docxtemplater-image-module,均为开源(docxtemplater 有收费 ...

  5. 【SpringMVC】获取请求参数

    通过ServletAPI获取 test.html <a th:href="@{/testServletAPI(username='admin',password=123456)}&qu ...

  6. Vue初体验(一)

    每个 Vue 应用都需要通过实例化 Vue 来实现. 语法格式如下: var vm = new Vue({ // 选项 }) 接下来让我们通过实例来看下 Vue 构造器中需要哪些内容: 可以看到在 V ...

  7. C# - 音乐小闹钟_BetaV3.0

    时间:2017-11-22 作者:byzqy 介绍: 音乐小闹钟 BetaV3.0 新鲜出炉了,快来围观吧!上效果图: 是不是觉得顿时变得高大上了许多呢?^_^ 工具/原料: (操作系统:Window ...

  8. 神舟G7-CT7NK 安装tensorflow-gpu

    参考https://www.cnblogs.com/xbit/p/9768238.html 直接安装,运行keras mnist数字识别报错: Could not create cudnn handl ...

  9. 20210805 noip31

    考场 没有一眼题 T1 想到先贪心地算出最大得分,任意构造出一种方案,不断调整以增大字典序. T2 发现在 \(x_k\) 确定的情况下操作次数就是左右两边的逆序对数,\(x_i\) 互不相同时直接找 ...

  10. 模拟9:T1:斐波那契

    Description: 题目描述:   小 C 养了一些很可爱的兔子.   有一天,小 C 突然发现兔子们都是严格按照伟大的数学家斐波那契提出的模型来进行繁衍:一对兔子从出生后第二个月起,每个月刚开 ...