O
Oreo
Hi there,
I am writing an application that needs to compute the exact size of a
file. I need for this function to work in Windows and UNIX.
One of my issues is that the length() method provided by the File
class does not return the exact size for all files.
The essence of my problem is that I cannot properly compute the size
of a directory or symbolic links in UNIX properly.
File.class() returns 0 for the size of directories regardless of OS.
This appears to be correct on Windows (right-click -> properties on an
empty directory in Windows). However this seems to be incorrect
according to Linux.
When compared to the output of ls, the File.length() method will not
return the proper length of directories (whether on a FAT or reiserfs
file system) or a symbolic link in UNIX. The length of a UNIX
directory is not zero, and the size of symbolic link is the length of
the filename that it points to.
When the windows partition is mounted in Linux, the size of the
directories on the windows partition are reported as being 4096 by
file system utilities ls and du. This contrasts the value of zero
reported by the Microsoft 98 Windows Explorer.
Detailed examples of my problem can be found at the following thread:
http://forum.java.sun.com/thread.jspa?threadID=574755
How can I compute a function that will be able to compute the size of
any file under any operating system?
I would like to avoid his path:
1. Determine if the class is being run in Windows or UNIX
2. If running in UNIX,
a. If a directory of symbolic link: execute : du -sb [file]
| awk '{print $1}'
or ls -al [file ] | awk ' { print $5 }'
b. Otherwise: File.length()
3. If running Windows, simply class File.length() (?)
By taking this route I need to perform an if() statement every time
the size of any file is being computed, and also execute an expensive
command for some special cases (when the file is a directory of link).
The expensive commands will be common, and I would like to avoid
having to do that.
- Oreo
I am writing an application that needs to compute the exact size of a
file. I need for this function to work in Windows and UNIX.
One of my issues is that the length() method provided by the File
class does not return the exact size for all files.
The essence of my problem is that I cannot properly compute the size
of a directory or symbolic links in UNIX properly.
File.class() returns 0 for the size of directories regardless of OS.
This appears to be correct on Windows (right-click -> properties on an
empty directory in Windows). However this seems to be incorrect
according to Linux.
When compared to the output of ls, the File.length() method will not
return the proper length of directories (whether on a FAT or reiserfs
file system) or a symbolic link in UNIX. The length of a UNIX
directory is not zero, and the size of symbolic link is the length of
the filename that it points to.
When the windows partition is mounted in Linux, the size of the
directories on the windows partition are reported as being 4096 by
file system utilities ls and du. This contrasts the value of zero
reported by the Microsoft 98 Windows Explorer.
Detailed examples of my problem can be found at the following thread:
http://forum.java.sun.com/thread.jspa?threadID=574755
How can I compute a function that will be able to compute the size of
any file under any operating system?
I would like to avoid his path:
1. Determine if the class is being run in Windows or UNIX
2. If running in UNIX,
a. If a directory of symbolic link: execute : du -sb [file]
| awk '{print $1}'
or ls -al [file ] | awk ' { print $5 }'
b. Otherwise: File.length()
3. If running Windows, simply class File.length() (?)
By taking this route I need to perform an if() statement every time
the size of any file is being computed, and also execute an expensive
command for some special cases (when the file is a directory of link).
The expensive commands will be common, and I would like to avoid
having to do that.
- Oreo