gpt4 book ai didi

java - 使用java IO将文件从本地复制到远程系统

转载 作者:行者123 更新时间:2023-12-02 04:09:17 25 4
gpt4 key购买 nike

我需要将文件从本地系统复制到远程系统,为此我使用以下代码:

    public class Autohost {

public static void main(String[] args) throws IOException {
InputStream in = new FileInputStream(new File(
"C:\\Users\\Jainesh_Trivedi\\Desktop\\WAR\\AutohostDemo1_1145.war"));

File f = new File("10.87.74.191\\C$\\IVS_Code\\tomcat\\apache-tomcat-7.0.57\\webapps\\AutohostDemo1_1145.war");
f.createNewFile();
OutputStream out = new FileOutputStream(f);
// Transfer bytes from in to out
byte[] buf = new byte[1024];
int len;

while ((len = in.read(buf)) > 0) {
out.write(buf, 0, len);



}
in.close();
out.close();


}
}

但我收到以下错误:

        Exception in thread "main" java.io.IOException: The system cannot find the path specified
at java.io.WinNTFileSystem.createFileExclusively(Native Method)
at java.io.File.createNewFile(Unknown Source)
at com.autohost2.java.Autohost.main(Autohost.java:18)

最佳答案

该行的文件名

File f = new File("10.87.74.191\\C$\\IVS_Code\\tomcat\\apache-tomcat-7.0.57\\webapps\\AutohostDemo1_1145.war");

不是有效的 UNC 路径。您需要两个反斜杠(在代码中是四个)来表示远程路径。修复版本:

File f = new File("\\\\10.87.74.191\\C$\\IVS_Code\\tomcat\\apache-tomcat-7.0.57\\webapps\\AutohostDemo1_1145.war");

还要确保远程计算机上的安全设置配置为允许您的帐户进行适当的访问。

关于java - 使用java IO将文件从本地复制到远程系统,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33950209/

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