gpt4 book ai didi

java - 如何在 Java 中通过网络将文件复制到 LocalDrive

转载 作者:行者123 更新时间:2023-12-01 05:52:37 24 4
gpt4 key购买 nike

我需要一个示例代码,用于通过网络将文件复制到 Java 中的本地文件系统。这是如何在 Java 中完成的?

最佳答案

这是在本地文件系统中复制文件的代码

 File fromfile = new File("file");
File tofile = new File("../copiedfile");
tofile.createNewFile();
FileInputStream from = new FileInputStream(fromfile);
FileOutputStream to = new FileOutputStream(tofile);
byte [] buffer = new byte[4096];
int bytesread;
while ((bytesread = from.read(buffer)) != -1) {
to.write(buffer, 0, bytesread);
}

我认为,如果你想通过网络复制文件,你应该使用ObjectOutput和套接字发送缓冲区

关于java - 如何在 Java 中通过网络将文件复制到 LocalDrive,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4187669/

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