简体   繁体   English

如何通过网络将文件复制到Java中的LocalDrive

[英]How to copy files over Network to LocalDrive in Java

I need a sample code that copies files over Network to Local File System in Java. 我需要一个示例代码,用于通过网络将文件复制到Java中的本地文件系统。 How this is done in Java? 用Java如何做到这一点?

here is code that copies files in the local file system 这是在本地文件系统中复制文件的代码

 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);
    }

I think, if you want to copy files over network you should send buffer using ObjectOutput and sockets 我认为,如果要通过网络复制文件,则应使用ObjectOutput和套接字发送缓冲区

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM