![](/img/trans.png)
[英]Error while trying to copy the file from one folder to a temp folder in JAVA [Access Denied]?
[英]Access denied when trying to move a video file to another folder (Java, Windows)
我正在尝试运行一个代码,该代码可以在 Windows 中将视频文件从一个文件夹移动到另一个文件夹,但我收到一条错误消息,提示访问被拒绝。
错误发生在我是:
i) 将文件从 C 驱动器文件夹移动到 D 驱动器文件夹
ii) 将文件从 D 盘文件夹移动到 C 盘文件夹
两者都显示了我试图将视频文件移动到的文件夹的错误访问被拒绝。 我认为在这里显示文件路径不安全,所以我不分享错误。 我只是技术和编程世界的新手,不知道这是不是真的。
我该如何解决这个问题,为什么会这样? 我运行的代码在下面可用。
public class TryUploadFile {
public static void main(String[] args) {
final int BUFFERSIZE = 4 * 1024;
Scanner s = new Scanner(System. in );
System.out.print("Enter source file path: ");
String sourceFilePath = s.nextLine();
System.out.println("Enter output file path: ");
String outputFilePath = s.nextLine();
try (
FileInputStream fin = new FileInputStream(new File(sourceFilePath));
FileOutputStream fout = new FileOutputStream(new File(outputFilePath));) {
byte[] buffer = new byte[BUFFERSIZE];
while (fin.available() != 0) {
fin.read(buffer);
fout.write(buffer);
}
}
catch(Exception e) {
System.out.println("Something went wrong! Reason: " + e.getMessage());
}
}
}
您可以尝试检查这些:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.