Win a copy of Java Concurrency Live Lessons this week in the Threads forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Serializing to a remote file?  RSS feed

 
Naseem Khan
Ranch Hand
Posts: 809
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All,

Can anyone please explain can I serialize the state of a serializable java object to a remote file.

Thanks in advance

Naseem
 
Ernest Friedman-Hill
author and iconoclast
Sheriff
Posts: 24215
37
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The only hard part is knowing how to write to the remote file: by file sharing, by an explicit network connection to a dedicated server, by HTTP or FTP, etc. Once you know how to open an OutputStream that goes to the file, then just construct an ObjectOutputStream that wraps that one, and call writeObject(), passing your object as an argument; then close the ObjectOutputStream.
 
Naseem Khan
Ranch Hand
Posts: 809
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well I tried this but it did not worked...



When I run this program, it returns true. But the size of the file remains zero even after serializing.

I tried both txt and ser extensions.

Any help will be appreciated.


Thanks in advance


Naseem
[ July 13, 2006: Message edited by: Naseem Khan ]
 
Joe Ess
Bartender
Posts: 9406
12
Linux Mac OS X Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You should know that the extension of a file has no impact on the content of the file. You can name an image file .JPG or .stupid, it does not change what the file is.
Your method returns true unless there's an exception. That doesn't mean that the code does what you want it to do, it just means that there hasn't been anything terribly wrong with the methods you have called.
The URL you are connecting to, is it a servlet/CGI that is capable of handling a file upload? HTTP is a request-response protocol. If you don't handle the response from your request, your request is likely never sent to the server. Are you debugging on the server side? Have you looked at the server logs?
 
Naseem Khan
Ranch Hand
Posts: 809
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Joe, , I am now using Servlet and sending a request to a servlet from java program.

Following thread helped me alot posted by Vijaishanker.

calling servlet from java program and more

Regards

Naseem
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!