java.io.FileNotFoundException: D:\e (拒绝访问。)
这是因为访问的文件地址是文件夹而不是,具体的文件,把路径改为具体的文件就可以了。
参考文章:https://blog.csdn.net/w405722907/article/details/78610485
/**
* 查看某个文件夹下所有的文件 并删除文件
*/
@RestController
public class One { /**
*查看某个文件夹下所有的文件
* @param args
*/
public static void main(String[] args) {
/*File file1 = new File("D:\\e\\test.txt");
delete(file1);
File file = new File("D:" + File.separator);
print(file);*/
//"D:\\门头沟国高新2018年度(管委).xlsx"
try {
download("门头沟国高新2018年度(管委).xlsx");
} catch (IOException e) {
e.printStackTrace();
}
/* String s = "D:/e/D:/门头沟国高新2018年度(管委).xlsx (文件名、目录名或卷标语法不正确。)";
String substring = s.substring(8, s.length());
System.out.println(substring);*/
} /**
* 打印某个文件夹下的所有文件名字
* @param file
*/
public static void print(File file){
if (file != null){
if (file.isDirectory()){
File[] files = file.listFiles();
if (files != null){
for (int i = 0; i < files.length; i++){
System.out.println(files[i]);
}
}
}
}
} /**
* 删除某个文件
* @param file
*/
public static void delete(File file){
if (file != null && file.exists()){
boolean delete = file.delete();
System.out.println(delete);
}
} /**
* 下载某个文件
* @param fileName
* @throws IOException
*/
public static void download(String fileName) throws IOException {
FileOutputStream fileOutputStream = null;
FileInputStream fileInputStream = null;
try {
fileInputStream = new FileInputStream("D:\\" + fileName);
fileOutputStream = new FileOutputStream("D:\\e\\" + fileName);
} catch (FileNotFoundException e) {
e.printStackTrace();
}
BufferedInputStream bufferedInputStream = new BufferedInputStream(fileInputStream);
BufferedOutputStream bufferedOutputStream = new BufferedOutputStream(fileOutputStream);
byte[] bytes = new byte[1024];
while (bufferedInputStream.read(bytes) != -1){
bufferedOutputStream.write(bytes);
}
bufferedOutputStream.flush();
bufferedOutputStream.close();
bufferedInputStream.close();
}
}
java.io.FileNotFoundException: D:\e (拒绝访问。)的更多相关文章
- java.io.FileNotFoundException:my-release-key.keyStore拒绝访问
安卓生成APK的时候,生成密钥的时候报java.io.FileNotFoundException:my-release-key.keyStore拒绝访问的错误 这是因为权限问题:你的jdk目录在c盘, ...
- Java解决java.io.FileNotFoundException: E:\work\work (拒绝访问。)
一.问题 在使用FileInputStream或FileOutputStream时会遇到如下问题1和问题2. 问题1: java.io.FileNotFoundException: .\xxx\xxx ...
- java.io.FileNotFoundException: E:\work\work (拒绝访问。)
转载自:https://blog.csdn.net/YQS_Love/article/details/51959776 一.问题 在使用FileInputStream或FileOutputStream ...
- 文件上传报错java.io.FileNotFoundException拒绝访问
局部代码如下: File tempFile = new File("G:/tempfileDir"+"/"+fileName); if(!tempFile.ex ...
- java.io.FileNotFoundException: D:\xxx\yyy (拒绝访问。)问题
File file=new File(fileAllName); FileWriter fw=new FileWriter(file); 在Java的 FileWriter 方法时 系统抛出了异常 j ...
- keytool 错误: java.io.FileNotFoundException: 拒绝访问
keytool 错误: java.io.FileNotFoundException: 拒绝访问 打开命令行,切换到D:\AndroidStudioProjects\MyApplication\app目 ...
- java.io.FileNotFoundException异常,一是“拒绝访问”,二是“系统找不到指定路径”
关于java.io.FileNotFoundException异常 因为这个异常抛出俩种情况:一是“拒绝访问”,二是“系统找不到指定路径” 这里只讲明什么时候抛拒绝访问,什么时候抛找不到指定路径. 原 ...
- Android java.io.FileNotFoundException:*** (Permission denied)
自从离开上海来到杭州之后,陆续接触了Android,Python,C++,OpenCV,最为一个新人来说,一路上遇到了很多坑,幸运的是 这互联网的强大(大傻子我还是蛮喜欢的哈),一路填填补补总算走了下 ...
- com.jcraft.jsch.JSchException: java.io.FileNotFoundException: file:\D:\development\ideaProjects\salary-card\target\salary-card-0.0.1-SNAPSHOT.jar!\BOOT-INF\classes!\keystore\login_id_rsa 资源未找到
com.jcraft.jsch.JSchException: java.io.FileNotFoundException: file:\D:\development\ideaProjects\sala ...
随机推荐
- vue-quill-editor 富文本框使用及上传图片到服务器
注:上传图片需要结合element-ui的upload上传 首先第一步:安装vue-quill-editor或quill两个模块 yarn add vue-quill-editor -D yarn a ...
- 如何在vue项目中引入element-ui
安装 elementUI npm install element-ui --save 引入elementUI import ElementUI from 'element-ui' import 'el ...
- Java System Reports
You use Java System Reports as a problem detection and analysis tool to: ● Monitor the AS Java ...
- robot framework笔记(三):扩展SeleniumLibrary库 (自定义关键字)
(一)自定义和浏览器相关的关键字 以下代码GitHub 版本库地址: https://github.com/blairwind/blog_rf SeleniumLibrary的扩展文档中提供了3种增加 ...
- EasyUI DataGrid 根据ID选中行(转载)
转载来源: https://blog.csdn.net/chq00788/article/details/51505519 function selectRows(){ //获取需要选中的记录ID ...
- python解析传入的命令行参数 argv
python解析命令行参数主要有三种方法:sys.argv.argparse解析.getopt解析 方法一:sys.argv —— 命令行执行:python test_命令行传参.py 1,2,3 1 ...
- 16寸屏苹果MacBook Pro悄悄上市,售价18999 元起步
传闻了半年之久的16寸屏苹果MacBook Pro于11月13日夜晚终于上线,15寸的机身16寸的屏幕,相比于此前的13寸和15寸MacBook Pro,新品搭配了更大的屏幕.更高性能的处理器以及更大 ...
- Vue路由实现页面跳转的两种方式(router-link和JS)
Vue.js 路由可以通过不同的 URL 访问不同的内容,实现多视图的单页 Web 应用 1.通过 <router-link> 实现 <router-link> 组件用于设置一 ...
- java基础(11)---模块(java9)
一.模块介绍 二.模块可以解决的问题 三.module-info.java文件 四.一个项目就可变成一个模块
- qingqing的项目
1 https://www.cnblogs.com/zhangqing979797/p/10147679.html 2 https://www.cnblogs.com/zhangqing979797/ ...