import java.io.BufferedOutputStream; import java.io.FileOutputStream; import java.io.InputStream; import java.net.Socket; class Main { public static void main(String[] args) { try { Socket sock = new Socket("127.0.0.1",8089); byte[] mybytearray = new byte[1024]; InputStream is =sock.getInputStream(); String filepath = "F:\\"+"p"+".csv"; FileOutputStream fos = new FileOutputStream(filepath); BufferedOutputStream bos = new BufferedOutputStream(fos); int byteRead = is.read(mybytearray , 0 , mybytearray.length); bos.write(mybytearray,0,byteRead); System.out.println("File sent to server"); bos.close(); sock.close(); } catch(Exception e) { System.out.println(e); } } }
import java.io.BufferedInputStream; import java.io.File; import java.io.FileInputStream; import java.io.IOException; import java.io.OutputStream; import java.net.ServerSocket; import java.net.Socket; class Main { public static void main(String[] args) { try { ServerSocket s = new ServerSocket(8089); String filepath = "E:\\"+"p"+".csv"; File myFile = new File(filepath); while (true) { Socket sock = s.accept(); byte[]mybytearray = new byte[(int) myFile.length()]; BufferedInputStream bis = new BufferedInputStream(new FileInputStream(myFile)); bis.read(mybytearray, 0, mybytearray.length); OutputStream os = sock.getOutputStream(); os.write(mybytearray, 0, mybytearray.length); System.out.println("file transfferd"); os.flush(); sock.close(); } } catch(Exception e) { System.out.println(e); } } }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)