• Post Reply Bookmark Topic Watch Topic
  • New Topic

passing file over a wire  RSS feed

 
sony gam
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
Is it possible to pass java.io.File object across the wire.
For example, if I have Example.xml file on my server side and now in my server class I have created a new File object, with just the relative path. (ie., Example.xml)
Now for a particular client request I want to send that file object over the wire to the client.
But when I actally tried to do this, I am getting a FileNotFoundException, as it is looking for Example.xml in the client directory.
I was wondering what could be the intent of the File object implementing Serializable interface.
Thanks,
Sony Gam
 
Jim Yingst
Wanderer
Sheriff
Posts: 18671
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
A File object only contains information about the path to a physical file - it does not contain the data from the file itself. It would have been better for them to call it the FilePath or FileName class instead, but it's too late to change now. If you want to send the file contents from server to client, you will need to copy the bytes over using some sort of stream. Create a FileInputStream to read bytes from the file, and an OutputStream which sends bytes to the client - then use a while loop to read from the InputStream and send the bytes to the OutputStream. Good luck.
 
sony gam
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Jim,
Thanks a lot for clearing that up.
But, as no Stream object is serailizable, this means that the server will need to parse the file into a byte[] in a while loop, as you suggested, and send it to the client.
This will require a while loop for every such operation.
I was wondering if there is no other way round.
Thanks,
Sony Gam
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!