0
我需要將文件從我的本地系統複製到遠程系統,爲了這個,我正在使用下面的代碼:文件複製使用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)
謝謝你解決了這個問題,但我得到了訪問被拒絕的異常,雖然我正在複製的文件夾有權限在文件夾中寫入@Ben N – jainesh
@jainesh對,機器不會讓任何人來在其中寫入和寫入。你需要做一些研究並配置適當的安全設置。 –
已將安全設置設置爲允許在文件夾上寫@Ben N – jainesh