gpt4 book ai didi

java.io.FileNotFoundException :

转载 作者:行者123 更新时间:2023-12-02 07:38:19 26 4
gpt4 key购买 nike

我尝试使用 Java 将单个文件从源复制到目标,但收到以下错误消息。

java.io.FileNotFoundException:以下是方法

public void copy_single(String source,String dest,String filename)
{
try
{ System.out.println(source + "" + filename);
System.out.println(dest + "" + filename);
File inputFile = new File(source+""+filename);
File outputFile = new File(dest+""+filename);
Process proc0 = Runtime.getRuntime().exec("chmod -R 777 "+inputFile+"");
proc0.waitFor();
Process proc1 = Runtime.getRuntime().exec("chmod -R 777 "+outputFile+"");
proc1.waitFor();
FileReader in = new FileReader(inputFile);
FileWriter out = new FileWriter(outputFile);
int c;
while ((c = in.read()) != -1)
out.write(c);
in.close();
out.close();
} catch(Exception e) {
e.printStackTrace();
System.out.println("Error: Operation failed!");
}
}

输出:-

/home/root/Tool/AAputDelta.sh
/home/root/Desktop/Sqa/BaseLine/Engine/AAputDelta.sh
java.io.FileNotFoundException: /home/root/Desktop/Sqa/BaseLine/Engine/AAputDelta.sh (No such file or directory)
at java.io.FileOutputStream.open(Native Method)
at java.io.FileOutputStream.<init>(FileOutputStream.java:194)
at java.io.FileOutputStream.<init>(FileOutputStream.java:145)

如何使用java复制简单文件。

最佳答案

怀疑部分或全部dest输出路径可能不存在。如果是这种情况,您可以使用 File.mkdirs构建路径。

此外,建议允许 File 而不是从字符串构建文件。处理所有这些,例如:

File inputFile = new File(source, filename);
File outputFile = new File(dest, filename);

关于java.io.FileNotFoundException :,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11903558/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com