I am trying to code a java socket server to send an image from this server to the navigator(client side). But when I send the image the file seen to be corrupted (display the image with symbols).
DataOutputStream dout = new DataOutputStream(connectS.getOutputStream());
String file="image.jpg";
File filename = new File(file);
FileInputStream fin = new FileInputStream(filename);
//dout.writeUTF(file);
System.out.println("Sending image...");
int size=(int) filename.length();
byte[] readData = new byte[size];
fin.read(readData);
dout.writeInt(size);
dout.flush();
dout.write(readData,0,size);
/*for(int i=0;i<readData.length;i++) {
dout.write(readData, 0, i);
}*/
dout.flush();
Here is how I start the program
ServerSocket ss=new ServerSocket(8080);
Socket connectS=ss.accept();
BufferedReader in=new BufferedReader(new InputStreamReader(connectS.getInputStream()));
Thanks for your help!!!