I am using normal Java Socket Programming to successfully transfer a known file. This is my code snippet:
Socket sock = new Socket("192.168.1.3", 6789);
byte[] mybytearray = new byte[9999];
InputStream is = sock.getInputStream();
FileOutputStream fos = new FileOutputStream("filename.txt");
BufferedOutputStream bos = new BufferedOutputStream(fos);
int bytesRead = is.read(mybytearray, 0, mybytearray.length);
bos.write(mybytearray, 0, bytesRead);
bos.close();
sock.close();
However in this code I have to explicitly name the receiving file as filename.txt, I want to retain the name of the file that is getting transferred. One way to do is to explicitly transfer the name of the file and then transfer the file (I think it is correct) OR is there any other way to do that?
The socket has no filename. You read bytes from the socket as they come, they could be anything.