Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > File object and serialization - information is lost

Reply
Thread Tools

File object and serialization - information is lost

 
 
Sebastian
Guest
Posts: n/a
 
      06-08-2011
Hello there,

I seem to misunderstand a thing about java.io.File. I wanted to use
the File object to transport information files existing in one place
(basically, a directory listing) to another place.

The API says File serves as an abstract representation of a file, and
that it implements Serializable.

However, after Serialization/Deserialization (in another JVM) the
methods lastModified() and length() return 0. This is not what I
expected.

Is there a standard object to transport this information, or do I have
to define my own?

-- Sebastian
 
Reply With Quote
 
 
 
 
Lothar Kimmeringer
Guest
Posts: n/a
 
      06-08-2011
Sebastian wrote:

> I seem to misunderstand a thing about java.io.File. I wanted to use
> the File object to transport information files existing in one place
> (basically, a directory listing) to another place.
>
> The API says File serves as an abstract representation of a file, and
> that it implements Serializable.


That should say it all. It only represents a file, but nothing more.

> However, after Serialization/Deserialization (in another JVM) the
> methods lastModified() and length() return 0. This is not what I
> expected.


Have a look into the source of java.io.File. The only member are
(copied from JDK 1.6.0):

/**
* This abstract pathname's normalized pathname string. A normalized
* pathname string uses the default name-separator character and does not
* contain any duplicate or redundant separators.
*
* @serial
*/
private String path;

/**
* The length of this abstract pathname's prefix, or zero if it has no
* prefix.
*/
private transient int prefixLength;

Only one value being serialized, the path. This doesn't come as
a surprise since it's only representing a file in an abstract
way and that's the path (including the filename).

> Is there a standard object to transport this information, or do I have
> to define my own?


When I was in need for something like this (for a GWT-application)
I implemented it myself because it was faster than searching the
Internet for something that contains all I need.


Regards, Lothar
--
Lothar Kimmeringer E-Mail: http://www.velocityreviews.com/forums/(E-Mail Removed)
PGP-encrypted mails preferred (Key-ID: 0x8BC3CD81)

Always remember: The answer is forty-two, there can only be wrong
questions!
 
Reply With Quote
 
 
 
 
Sebastian
Guest
Posts: n/a
 
      06-08-2011
Am 08.06.2011 20:18, schrieb Lothar Kimmeringer:
> Sebastian wrote:
>
>> I seem to misunderstand a thing about java.io.File. I wanted to use
>> the File object to transport information files existing in one place
>> (basically, a directory listing) to another place.
>>

[snip]
>
> When I was in need for something like this (for a GWT-application)
> I implemented it myself because it was faster than searching the
> Internet for something that contains all I need.
>
>
> Regards, Lothar


Thanks for pointing out the source. I'll do as you did...
-- Sebastian

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
how to move from java object serialization to xml serialization? Dimitri Ognibene Java 4 09-02-2006 07:32 AM
Object serialization XML vs java serialization plasticfloor@gmail.com Java 3 06-14-2006 03:45 AM
Serialization Problems and books on serialization? sinleeh@hotmail.com Java 8 01-02-2005 02:40 PM
avoiding XML serialization, different WSDL generation, soap serialization Ramunas Urbonas ASP .Net Web Services 1 07-27-2004 09:57 PM
info on object serialization and file indexing? Jeffrey Drew Java 1 10-06-2003 04:04 PM



Advertisments