提问人:Fra 提问时间:8/9/2023 最后编辑:Mark RotteveelFra 更新时间:8/9/2023 访问量:40
如何将文件保存在同一网络内的另一台计算机中,知道 IP 地址和路径
How to save a file in another computer within the same network knowing IP address and path
问:
我必须将文件从服务器移动到另一台服务器。我可以连接到源服务并通过 smb 检索文件,但是一旦我有了文件,我就可以毫无问题地将其保存在我的机器上,但是我在将其复制到另一台服务器时遇到了麻烦。目标服务器是 Windows 计算机,我知道 IP 地址和要将文件保存到的文件夹。 根据我收到的错误,我认为目标路径上有问题。
这是我正在使用的:
public static void main(String args[]) throws Exception {
String from = "smb://IpAddress/.../tmp/";
String toServer = "//.... what should i write here??";
String filename = "someFileName.xml";
moveSmbFileToServer(from, toServer, filename);
} // main
public static void moveSmbFileToServer (String smbPathFrom, String pathTo, String fileName) throws Exception {
SmbFile smbFileFrom = new SmbFile(smbPathFrom + fileName);
File fileTo = new File(pathTo + fileName);
InputStream is = null;
OutputStream os = null;
try {
is = smbFileFrom.getInputStream();
os = new FileOutputStream(fileTo);
byte[] buffer = new byte[1024];
int length;
while ((length = is.read(buffer)) > 0)
os.write(buffer, 0, length);
// smbFileFrom.delete(); // commented so I can test multiple times. Will be uncommented once the writing works
} finally {
is.close();
os.close();
}
} // moveSmbFileToServer
答: 暂无答案
评论