java - How to send a directory of files -


i need change code send directory of image files @ moment sends 1 file, main goal have ask directory , send of files in directory (image files) server need display how data sent code have is:

client:

package sockets; import java.net.*; import java.io.*;  public class client {      public static void main (string [] args ) throws ioexception {         int filesize=1022386;         int bytesread;         int currenttot = 0;         socket socket = new socket("127.0.0.1",6789);         byte [] bytearray  = new byte [filesize];         inputstream = socket.getinputstream();         fileoutputstream fos = new fileoutputstream("copy.txt");         bufferedoutputstream bos = new bufferedoutputstream(fos);         bytesread = is.read(bytearray,0,bytearray.length);         currenttot = bytesread;         system.out.println("the size of data transferred " + bytesread + " bytes");          {            bytesread =               is.read(bytearray, currenttot, (bytearray.length-currenttot));            if(bytesread >= 0) currenttot += bytesread;         } while(bytesread > -1);          bos.write(bytearray, 0 , currenttot);         bos.flush();         bos.close();         socket.close();       } } 

server:

package sockets; import java.net.*; import java.io.*; public class server {    public static void main (string [] args ) throws ioexception {`              serversocket serversocket = new serversocket(6789);               socket socket = serversocket.accept();               system.out.println("accepted connection : " + socket);               file transferfile = new file ("orders.txt");               byte [] bytearray  = new byte [(int)transferfile.length()];               fileinputstream fin = new fileinputstream(transferfile);               bufferedinputstream bin = new bufferedinputstream(fin);               bin.read(bytearray,0,bytearray.length);               outputstream os = socket.getoutputstream();               system.out.println("sending files...");               os.write(bytearray,0,bytearray.length);               os.flush();               socket.close();               system.out.println("file transfer complete");             } } 

thank you

iterate on files in selected directory , known image extensions want send.

here's example iterating on files.

then, stream bytes in each of files client server.

i suggest using ftp sending files server established protocol precisely type of problem.


Comments

Popular posts from this blog

Detect support for Shoutcast ICY MP3 without navigator.userAgent in Firefox? -

web - SVG not rendering properly in Firefox -

java - JavaFX 2 slider labelFormatter not being used -