File object and serialization - information is lost

Discussion in 'Java' started by Sebastian, Jun 8, 2011.

  1. Sebastian

    Sebastian Guest

    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
    Sebastian, Jun 8, 2011
    #1
    1. Advertising

  2. 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:
    PGP-encrypted mails preferred (Key-ID: 0x8BC3CD81)

    Always remember: The answer is forty-two, there can only be wrong
    questions!
    Lothar Kimmeringer, Jun 8, 2011
    #2
    1. Advertising

  3. Sebastian

    Sebastian Guest

    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
    Sebastian, Jun 8, 2011
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Replies:
    8
    Views:
    2,233
    deadsea
    Jan 2, 2005
  2. Replies:
    3
    Views:
    1,022
  3. Dimitri Ognibene
    Replies:
    4
    Views:
    776
    Dimitri Ognibene
    Sep 2, 2006
  4. OHM
    Replies:
    1
    Views:
    404
  5. Ramunas Urbonas
    Replies:
    1
    Views:
    391
    Dino Chiesa [Microsoft]
    Jul 27, 2004
Loading...

Share This Page