我正在将一个文件下载到我的电脑中,然后将其移动到“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(); } }对于重复声明者, 我尝试了此解决方案Solution-1 Solution-2 Solution-3但没有解决问题这个例外在我看来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)
添加回答
举报
0/150
提交
取消