I have the following code:
List<FileItem> items = uploadHandler.parseRequest(request);
for (FileItem item : items) {
if (!item.isFormField()) {
File file = new File("D:/Data");
}
}
When I am trying to save a file, I am getting the following error
java.io.FileNotFoundException: D:\Data (Access is denied.)
What could be the reason and how can I resolve this? I do have read and write permission on this folder.
This question is related to
java
filenotfoundexception
Make sure that the directory exists, you have permission to access it and add the file to the path to write the log:
File file = new File("D:/Data/" + item.getFileName());
You need to set permission for the user controls .
Not exactly the case of this question but can be helpful. I got this exception when i call mkdirs() on new file instead of its parent
File file = new java.io.File(path);
//file.mkdirs(); // wrong!
file.getParentFile().mkdirs(); // correct!
if (!file.exists()) {
file.createNewFile();
}
I have search for this problem and i got the following answers:
"C:\Program Files\Apache-tomcat-7.0.69\"
remove the extra backslash (\
)Your problem will be solved
Source: Stackoverflow.com