如何将文件从文件夹移动到文件夹

问题描述 投票:0回答:1

我将一个文件下载到我的PC中,然后将其移入

“C:/ Program Files(x86)/MyProgram/sample.txt”

问题是当我试图将文件从下载文件移动到目的地时

这是我的代码

String website ="https://www.sample-videos.com/text/Sample-text-file-100kb.txt";
       try (InputStream in = URI.create(website).toURL().openStream()) {
         long x=Files.copy(in, Paths.get("C:/Users/Big Foot/Downloads/sample1.txt"));
         System.out.println(x); 
         in.close();
         File dest = new File("C:/Program Files (x86)/myProgram/sample.txt");
         File source = new File("C:/Users/Big Foot/Downloads/sample1.txt");
         try {
             FileUtils.moveFile(source, dest);
         } catch (IOException e) {
             e.printStackTrace();
         }
       }

对于Duplicate Claimers我试过这个解决方案Solution-1 Solution-2 Solution-3But没有解决问题

这种例外对我来说很明显

java.io.FileNotFoundException: C:\Program Files (x86)\Excell To Access Convertor\sample.txt (Access is denied)
at java.io.FileOutputStream.open0(Native Method)
at java.io.FileOutputStream.open(Unknown Source)
at java.io.FileOutputStream.<init>(Unknown Source)
at java.io.FileOutputStream.<init>(Unknown Source)
at org.apache.commons.io.FileUtils.doCopyFile(FileUtils.java:1123)
at org.apache.commons.io.FileUtils.copyFile(FileUtils.java:1076)
at org.apache.commons.io.FileUtils.copyFile(FileUtils.java:1028)
at org.apache.commons.io.FileUtils.moveFile(FileUtils.java:3008)
at download.main(download.java:31)
java file access denied
1个回答
2
投票

没有管理员权限,您无法在C:\Program Files (x86)\中编写或修改文件。以管理员身份运行程序是解决此问题的最简单方法。

© www.soinside.com 2019 - 2024. All rights reserved.