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 ...
随机推荐
- React学习:状态(State) 和 属性(Props)
State 与 Props 区别props 是组件对外的接口,state 是组件对内的接口.组件内可以引用其他组件,组件之间的引用形成了一个树状结构(组件树),如果下层组件需要使用上层组件的数据或方法 ...
- STM32F10x芯片类型 STM32F10X_LD STM32F10X_MD STM32F10X_HD STM32F10X_XL STM32F10X_CL
stm32f10x.h 固件库stm32f10x.h中有如下解释 #if !defined (STM32F10X_LD) && !defined (STM32F10X_LD_VL) & ...
- 笔谈runloop(一)
关于runloop熟悉而又陌生,熟悉的是在iOS开发的过程中线程的执行就跟runloop扯上关系了,陌生的是runloop到底是个什么东西.去公司面试的时候,很多公司的面试人员会问这个问题.runlo ...
- 设置Redis集群访问密码(不停机设置)
依次登陆6个节点 cd /mysystest ./redis/bin/redis-cli -c -h 192.168.43.86 -p 7301 执行以下命令 config set masterau ...
- Python学习日记(七) 文件操作
文件操作: 首先要有一个文件作为对象,例‘文件名’.txt 1.文件路径:例 d:\文件名.txt <1>:绝对路径:从根目录往后的路径 <2>:相对路径:当前目录下的路径有什 ...
- workman 使用心得
1. 服务端调试: 直接在 Events.php 中 echo 变量, 即可在 命令行工具中 看到输出的信息. 以便进行调试. 2. 客户端调试: 由于是js代码, 可以直接 用 conso ...
- Ceph分布式存储部署过程
前言: 环境介绍:此次部署系统为Cenots 7 MON.OSD 10.110.180.112 Admin MON.OSD 10.110.180.113 Node1 MON.OSD 10.110.18 ...
- Python——元组
是为了满足,某些值当被定义以后就不可修改或删除而出现的元组形式. 特点: 元组中的元素不可被修改或删除 没有独立的功能 可以进行嵌套,当嵌套方可以修改删除时,可以对嵌套方进行. 元组可以进行公共功能中 ...
- oracle更改数据库字符集
shutdown immediate; startup mount; alter system enable restricted session; alter system set job_queu ...
- 《你说对就队》第七次作业:团队项目设计完善&编码
<你说对就队>第七次作业:团队项目设计完善&编码 项目 内容 这个作业属于哪个课程 [教师博客主页链接] 这个作业的要求在哪里 [作业链接地址] 团队名称 <你说对就队> ...