局部代码如下:

  1. File tempFile = new File("G:/tempfileDir"+"/"+fileName);
  2. if(!tempFile.exists()){
  3. tempFile.mkdirs();
  4. System.out.println(tempFile.exists());
  5. }

运行后发现,新建的目录里面应该是个文件,但是确实个路径

然后修改代码如下

  1. File tempFile = new File("G:/tempfileDir"+"/"+fileName);
  2. if(!tempFile.getParentFile().exists()){
  3. tempFile.getParentFile().mkdirs();//创建父级文件路径
  4. tempFile.createNewFile();//创建文件
  5. System.out.println(tempFile.exists());
  6. }

报错java.io.FileNotFoundException,导致拒绝访问,往往是没有相关文件或者是文件和路径创建时调用方法调用错了,需要注意。

文件上传报错java.io.FileNotFoundException拒绝访问的更多相关文章

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

  2. 解决springMVC文件上传报错: The current request is not a multipart request

    转自:https://blog.csdn.net/HaHa_Sir/article/details/79131607 解决springMVC文件上传报错: The current request is ...

  3. 完美解决JavaIO流报错 java.io.FileNotFoundException: F:\ (系统找不到指定的路径。)

    完美解决JavaIO流报错 java.io.FileNotFoundException: F:\ (系统找不到指定的路径.) 错误原因 读出文件的路径需要有被拷贝的文件名,否则无法解析地址 源代码(用 ...

  4. keytool 错误: java.io.FileNotFoundException: 拒绝访问

    keytool 错误: java.io.FileNotFoundException: 拒绝访问 打开命令行,切换到D:\AndroidStudioProjects\MyApplication\app目 ...

  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. .net core 3.0web_razor page项目_使用中间件接受大文件上传报错_httpRequest.Form threw an exception of type Microsoft.AspNetCore.Server.Kestrel.Core.BadHttpRequestException_Request body too large

    前言:在web项目的.net framework时文件上传时,自己常用一般处理程序接受上传文件,上传文件的大小限制是可以项目的webconfig里配置.   到core项目使用一般处理程序变成了中间件 ...

  8. springboot文件上传报错

    异常信息: org.springframework.web.multipart.MultipartException: Could not parse multipart servlet reques ...

  9. 文件上传报错:Unknown: file created in the system's temporary directory

    nginx+php下文件上传成功,但会有错误提示如下: <b>Notice</b>:  Unknown: file created in the system's tempor ...

随机推荐

  1. 498. (leetcode)对角线遍历

    498. 对角线遍历 根据题目的图像看,主要有两种走法,第一种是向右上(顺时针方向),第二种是向左下(逆时针)走 我们设 x ,y初始为0,分别对应横纵坐标 现在分析右上(0,2) 为例:(注意右上的 ...

  2. python 基础之浅拷贝与深拷贝

    浅拷贝与深拷贝 1.普通赋值 例1: a = 15b = aa = 16print(b)#例2:lst1 = [1,2,3]lst2 = lst1lst1.append(4)print(lst2)#这 ...

  3. redis 之redis发布订阅

    Redis 通过 PUBLISH . SUBSCRIBE 等命令实现了订阅与发布模式. 一个Publisher,多个Subscriber模型 如下图所示,可以作为消息队列或者消息通道 主要应用: 一个 ...

  4. SpringBoot 集成MyBatis、事务管理

    集成MyBatis (1)在pom.xml中添加依赖 <!-- mybatis的起步依赖.包含了mybatis.mybatis-spring.spring-jdbc(事务要用到)的坐标 --&g ...

  5. Python 爬取 北京市政府首都之窗信件列表-[后续补充]

    日期:2020.01.23 博客期:131 星期四 [本博客的代码如若要使用,请在下方评论区留言,之后再用(就是跟我说一声)] //博客总体说明 1.准备工作 2.爬取工作(本期博客) 3.数据处理 ...

  6. 一定要熟练地使用常用的Foundation服务

    关于本文:作为一名iOS软件工程师,熟练的使用系统提供的强大的Foundation服务是必备的职业素养. NSString.NSMutableString NSArray.NSMutableStrin ...

  7. new Vue() 和 export default {}及Vue页面组件和标签组件说明与比较(非常重要)

    说明与比较:new Vue() 和 export default {} (1)vue就是一个构造函数 (2)vue标签组件:是HTML标签的扩展https://www.cnblogs.com/w-wa ...

  8. 五、java基础-关键字this_static_super_abstract_final,finalize()方法finally语句块

    1.关键字this 含义:this 是一个引用类型,代表当前对象,引用类型里面必然保存内存地址,在堆中的每个对象中存储,保存内存地址指向自身. 用法: 1)this可以用在成员方法中,里面保存内存地址 ...

  9. IDEA配置数据库连接失败的问题

    今天采用IDEA连接数据库失败了,有几个问题需要注意 首先笔者采用的数据库版本为8.0.17而IDEA自带版本是5.2.26大概,于是首先出现的问题是驱动不匹配,那么就需要换成我自己的版本,配置如下 ...

  10. jQuery父级以及同级元素查找的实例

    父级以及同级元素的查找在使用过程中还是蛮频繁的,下面为大家介绍下jQuery是如何实现的,感兴趣的朋友可以参考下 jQuery.parent(expr) 找父亲节点,可以传入expr进行过滤,比如$( ...