[英]File Copy from local to remote system using java IO
我需要將文件從本地系統復制到遠程系統,為此,我使用以下代碼:
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");
還要確保將遠程計算機上的安全設置配置為允許您的帳戶進行適當的訪問。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.