开发者

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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜