Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Help Regarding saving of received files  RSS feed

 
Varun Nambuthiri
Ranch Hand
Posts: 76
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi

I am trying to receive files over a network and I am using Object I/O to do so . See for "sending" file I am



and for receiving the file



thanks in advance ..
 
Joanne Neal
Rancher
Posts: 3742
16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Did you have a question ?
 
Varun Nambuthiri
Ranch Hand
Posts: 76
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes ... Ok it seems its become ambiguous .

What I wanted to know was can I can transfer any type of file using Object I/O ?
 
Jeff Verdegan
Bartender
Posts: 6109
6
Android IntelliJ IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Varun Nambuthiri wrote:Yes ... Ok it seems its become ambiguous .

What I wanted to know was can I can transfer any type of file using Object I/O ?


You cannot transfer files at all using Object I/O. You can only transfer Java objects. (I assume by "Object I/O" you mean Java's serialization using ObjectInputStream and ObjectOutputStream.) So, if you want to transfer a file's contents using "object I/O", you would need to first devise a way to turn that file's contents into a Java object that implements Serializable. Or find a library that does.

This is not necessarily hard. A simple String or byte[] might suffice. However, it is also probably not necessary. If you want to send and receive a file's contents, you really don't need Object(Output|Input)Stream at all. You just need to read and write byte buffers.

As a side note, your file_object makes me suspect that you think that java.io.File is somehow a representation of a File's contents. It is not. It has nothing to do with the file's contents at all. It is simply, as the javadoc states right at the beginning: "An abstract representation of file and directory pathnames." The File object is in fact serializable, but if you serialize it, you're really just passing a file's pathname back and forth.

So, finally, I have to ask, what are you actually trying to accomplish? If you're still having difficulty, take a step back and explain what problem you're trying to solve where you thought that "transferring a fille using Object I/O" would be a solution.
 
Varun Nambuthiri
Ranch Hand
Posts: 76
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for the comprehensive and yet a needed lesson on Serialization. I found where I made a mistake as I was trying to transfer files from one client to another all I needed to do was use FileInputStream or FileOutputStream . Sillly of me!

Well now my question is can transfer all of types of files using just File I/O ?
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!