[英]Error while trying to copy the file from one folder to a temp folder in JAVA [Access Denied]?
I am trying to copy a bunch of files from one folder to a temp folder using java but its giving me File not found error(Access Denied) 我试图使用java将一堆文件从一个文件夹复制到临时文件夹,但它给我找不到文件错误(访问被拒绝)
The code snippet is:
代码段是:
` // defining path `//定义路径
Path userDir = Paths.get("somePathString");
Path tempDir = Files.createTempDirectory(userDir, tempFolder);
// creating file
File userDirFile = new File(userDir.toString());
File tempDirFile = new File((tempDir).toString());
FileCopyUtils.copy(userDirFile, tempDirFile);
tempDirFile.deleteOnExit();`
Output
产量
` java.io.FileNotFoundException: C:\gitProjects\server\bin\newfolder (Access is denied)
at java.io.FileInputStream.open0(Native Method)
at java.io.FileInputStream.open(Unknown Source)
at java.io.FileInputStream.<init>(Unknown Source)
at org.springframework.util.FileCopyUtils.copy(FileCopyUtils.java:63)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:26)
at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:27)
at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:86)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:459)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:675)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:382)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:192)
`
I have had this problem with Netbeans. 我遇到过Netbeans这个问题。 With a Netbeans package you don't want to place your files directly in the src folder.
使用Netbeans包,您不希望将文件直接放在src文件夹中。 Instead you want them just inside the package folder.
相反,你只需要在包文件夹中。
Also it looks like your (Access is denied). 它看起来像你的(访问被拒绝)。 Every file is given a permission which means that only certain users can access that file.
每个文件都有权限,这意味着只有特定用户才能访问该文件。 Here is the Windows direction to changing file permissions.
以下是更改文件权限的Windows方向。
You need to set permission for the user controls . 您需要为用户控件设置权限。
Goto C:\\Program Files\\ Right click java folder, click properties. 转到C:\\ Program Files \\右键单击java文件夹,单击属性。 Select the security tab.
选择安全选项卡。 There, click on "Edit" button, which will pop up PERMISSIONS FOR JAVA window.
在那里,点击“编辑”按钮,弹出PERMISSIONS FOR JAVA窗口。 Click on Add, which will pop up a new window.
单击“添加”,将弹出一个新窗口。 In that, in the "Enter object name" box, Enter your user account name, and click okay(if already exist, skip this step).
在其中,在“输入对象名称”框中,输入您的用户帐户名,然后单击“确定”(如果已存在,请跳过此步骤)。 Now in "PERMISSIONS OF JAVA" window, you will see several clickable options like CREATOR OWNER, SYSTEM, among them is your username.
现在在“PAVISSIONS OF JAVA”窗口中,您将看到几个可点击的选项,如CREATOR OWNER,SYSTEM,其中包括您的用户名。 Click on it, and check mark the FULL CONTROL option in Permissions for sub window.
单击它,选中“子窗口权限”中的“完全控制”选项。 Finally, Hit apply and okay.
最后,点击申请,好吧。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.