I've a client and a server. The server maintains a File and the client does a request for it. So, what I do is
File CONFIGURATION_FILE=new File(configuration.doc);
System.out.println (CONFIGURATION_FILE.exist()); //return true
in=new BufferedReader(new InputStreamReader(socket.getInputStream()));
oos=new ObjectOutputStream(socket.getOutputStream());
String line;
while ((line=in.readLine())!=null) {
if (line.equals("configuration file"))
oos.writeObject(CONFIGURATION_FILE);
oos.flush();
}
}
When I receive on the client the File, it throws an IOException. The program works if I pass the absolute path when I create the File (client and server are on the same machine for the moment, so I think that what is passed through the socket is a reference to the path and both the client and the server can see that). My question is: Is possible sending a File as an Object through the socket channel directly or I must convert it to an array of bytes and send this array? Thank you in advance
"abstract representation of file and directory pathnames"(javadoc). So no, you can't just send it through a socket. You can hovewer use NIO to simplify the handling of the streams.Filereally should have been calledPath, but it's too late for them to fix it now.