简体   繁体   中英

How to create folder in root folder of the project?

In my project I'm trying to upload files to a drive in my system and when i try to access the file using browser it shows **Not allowed to load local resource: ** error. I think creating and uploading files to the project folder may solve the issue. How to do that programmatically in java?

private final String UPLOAD_DIRECTORY = "D:/dy/Stock";

File filee = new File(UPLOAD_DIRECTORY);

                if (!filee.exists()) {

                    filee.mkdir();

                }
name = new File(item.getName()).getName();

item.write(new File(UPLOAD_DIRECTORY + File.separator + name));

This is the codeI used to create and upload files to folder.

It won't. As a general rule, doing file:// anything in a browser, these days, just does not work. Why not? It's complicated, but, to oversimplify: Security.

It has nothing whatsoever to do with the access rights of the process that asks the browser to load em. The browser just will not do this.

The solution, if you want to have resources open in a browser window from a locally running app, is to have your locally running app boot up a webserver (locally), and then ask the browser to load not, say:

file:///Users/alvin/proj/myfile.txt

but to ask the browser to load, say:

http://localhost:8192/myfile.txt

... which would work, if you start a webserver on 8192.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM