user75ponic user75ponic - 2 years ago 158
Java Question

Access is denied

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 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.

Answer Source

When you call new File your are supposed to give the file name, not only the directory you want to put your file in.

Try with something like

File file = new File("D:/Data/" + item.getFileName());
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download