简体   繁体   English

如何在项目的根文件夹中创建文件夹?

[英]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?如何在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.作为一般规则,如今在浏览器中执行file://任何操作都行不通。 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.它与要求浏览器加载 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. ...如果您在 8192 上启动网络服务器,这会起作用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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