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 ...
随机推荐
- css文字的渐变色设置
background-image: -webkit-linear-gradient( ); //设置颜色与渐变方向 -webkit-background-clip: text; //主要用于剪 ...
- element-ui 穿梭框使用axios数据查询
//class="input"样式自写,用来覆盖穿梭框自带的搜索,它自带的搜索框不能搜索外部数据,只能查询在穿梭框内的数据 <div style="text-ali ...
- Jmeter学习笔记(十六)——HTTP请求之content-type
一.HTTP请求Content-Type 常见的媒体格式类型如下: text/html : HTML格式 text/plain :纯文本格式 text/xml : XML格式 image/gif :g ...
- Apache Commons FileUpload实现文件上传
一.Apache Commons-FileUpload简介 Apache Commons是一个专注于可重用Java组件的所有方面的 Apache 项目. Apache Commons项目由三个部分组成 ...
- python两则99乘法表
分别应用while和for的嵌套循环,适用于初学的人看看 x = 1 while x <= 9: y = 1 while y <= x: print (y,'*',x,'=',x*y,en ...
- MySQL加锁分析 (转)
参考:MySQL 加锁处理分析.该文已经讲的很详尽了,也易懂,下面仅仅是个人做的总结. 一. 背景 1.1 隔离级别 1.2 加锁过程 逐条处理,逐条加锁. 1.3 两阶段锁2PL 1.4 gap锁 ...
- Linux关闭防火墙、设置端口
关闭防火墙 1)重启后生效 开启: chkconfig iptables on 关闭: chkconfig iptables off 验证防火墙是否关闭:chkconfig --list |grep ...
- WCF 学习系列——WCF的学习基础
这个系列的博客由WCF4 高级编程学习记录,如有错误请指正. 首先介绍一些概念: SOA: (Service-Oriented Architecture 面向服务架构),一种架构方法,也是一种编程模式 ...
- [转]LINUX最大线程数及最大进程数
原文:https://blog.csdn.net/wowocpp/article/details/86673886 --------------------- cat /proc/sys/kernel ...
- machine learning (6)---how to choose features, polynomial regression
how to choose features, polynomial regression:通过定义更适合我们的feature,选择更好的模型,使我们的曲线与数据更好的拟合(而不仅仅是一条直线) 可以 ...