File object and serialization - information is lost

S

Sebastian

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
 
L

Lothar Kimmeringer

Sebastian said:
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: (e-mail address removed)
PGP-encrypted mails preferred (Key-ID: 0x8BC3CD81)

Always remember: The answer is forty-two, there can only be wrong
questions!
 
S

Sebastian

Am 08.06.2011 20:18, schrieb Lothar Kimmeringer:
Sebastian said:
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,774
Messages
2,569,599
Members
45,174
Latest member
BlissKetoACV
Top