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.

03-24-2010, 09:14 PM

JosAH

Quote:

Originally Posted by tfitz666

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

03-24-2010, 09:39 PM

tfitz666

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.

03-24-2010, 09:57 PM

iluxa

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.

03-24-2010, 09:57 PM

JosAH

Quote:

Originally Posted by tfitz666

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.