Results 1 to 6 of 6
  1. #1
    tfitz666 is offline Member
    Join Date
    Jul 2009
    Posts
    21
    Rep Power
    0

    Default Reading file atributes in java??

    Hi,
    I've been given an assignment to write a client/server program where the client sends the name of a file to the server and the server replies with the file attributes(size, permissions etc.) I've written the client and server already but cant find how to get the files attributes. This will only be run on linux if that helps. Any idea how to get the attributes? Thanks in advance.

  2. #2
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,457
    Blog Entries
    7
    Rep Power
    20

    Default

    Quote Originally Posted by tfitz666 View Post
    Hi,
    I've been given an assignment to write a client/server program where the client sends the name of a file to the server and the server replies with the file attributes(size, permissions etc.) I've written the client and server already but cant find how to get the files attributes. This will only be run on linux if that helps. Any idea how to get the attributes? Thanks in advance.
    Did you read the API documentation for the File class?

    kind regards,

    Jos

  3. #3
    tfitz666 is offline Member
    Join Date
    Jul 2009
    Posts
    21
    Rep Power
    0

    Default

    Yes, it was the first thing I read. The api has methods to test whether the application can read or write to the file, but I was hoping for somthing more like what you get if you type ps -al in terminal. Also the file API has nothing to say the size.

  4. #4
    iluxa is offline Senior Member
    Join Date
    Mar 2010
    Posts
    266
    Rep Power
    5

    Default

    File.length () returns the size of the file in bytes.

    As far as permissions, Java doesn't provide these on purpose since they're platform-dependent... the only thing you can do, really, is Runtime.getRuntime().exec ("ls -al") and parse the output.

  5. #5
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,457
    Blog Entries
    7
    Rep Power
    20

    Default

    Quote Originally Posted by tfitz666 View Post
    Yes, it was the first thing I read. The api has methods to test whether the application can read or write to the file, but I was hoping for somthing more like what you get if you type ps -al in terminal. Also the file API has nothing to say the size.
    The user/group/other distinction is a unixism so it isn't suported by Java (without JNI) because of its platform neutral design.

    kind regards,

    Jos

  6. #6
    tfitz666 is offline Member
    Join Date
    Jul 2009
    Posts
    21
    Rep Power
    0

Similar Threads

  1. Replies: 0
    Last Post: 11-24-2009, 01:49 PM
  2. Replies: 0
    Last Post: 07-15-2009, 01:46 PM
  3. Replies: 3
    Last Post: 05-09-2009, 11:31 PM
  4. Reading a file into java and give it out
    By little_polarbear in forum New To Java
    Replies: 7
    Last Post: 06-05-2008, 10:32 AM
  5. Question abt.reading xml file using java
    By gvi in forum Advanced Java
    Replies: 6
    Last Post: 11-08-2007, 05:48 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •