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+Ts项目时出现:Module build failed (from ./node_modules/css-loader/dist/cjs.js): CssSyntaxError
具体错误 ERROR in ./src/index.tsx Module build failed (from ./node_modules/css-loader/dist/cjs.js): CssS ...
- viewer与 iview Carousel(走马灯) 结合使用,图片无法显示
问题原因:iview Carousel (走马灯)在加载是如果没有图片 它没有高度.之后给src赋值,图片无法显示,拖动一下浏览器宽或搞它就会显示. 走马灯解决这个问题方法:1在Carousel或其父 ...
- Mac 修改hostname
mac终端上输入命令: sudo scutil --set HostName newname # 实例 sudo scutil --set HostName master
- 限制mongoDB内存的方法
docker运行MongoDB,针对于docker容器来进行内存资源的限制 修改MongoDB的运行配置文件,并且重启mongodb storage: dbPath: /var/lib/mongodb ...
- 【转】CCS5.5从硬盘读入.dat数据格式的单张图像
首页 博客 学院 CSDN学院 下载 论坛 APP CSDN 问答 商城 活动 VIP会员 ...
- array_push
array_push() 函数向第一个参数的数组尾部添加一个或多个元素(入栈),然后返回新数组的长度. 该函数等于多次调用 $array[] = $value. 1:即使数组中有字符串键名,您添加的元 ...
- 使用ImageMagick在Linux系统上截图
ImageMagick安装指令: sudo apt-get install imagemagick 安装完成后,输入 import screenshot.png 命令就可以开始截图.此时鼠标图标会变成 ...
- WebService接口学习【1】
工具: 1.Eclipse(or)IDEA编辑器 2.SoapUI测试工具 1.wsdl文件标签体的约束: 一:namespace:相当于文件的id 二:targetNamespace属性:用来指定s ...
- C++ --- 编码习惯小区别
定义一个变量,最好养成C代码的习惯 C代码: 用到的变量X,要在最开始定义:先定义,用的时候在初始化: [例如] int x; //先定义 ..... ..... ; //再初始化 C++代码: 用到 ...
- codevs 1341 与3和5无关的数
题目描述 Description 有一正整数a,如果它能被x整除,或者它的十进制表示法中某位上的数字为x,则称a与x相关.现求所有小于等于n的与3或5无关的正整数的平方和. 输入描述 Input De ...