简体   繁体   中英

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. How this is done in 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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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