1> for a empty directory, linux command du will show 0 size, that means it does not use disk space. right? but File.length() in java will not show zero, instead it show the empty directory used some bytes.
If it is true that everything in Unix is a file and should take up disk space, then Java is right here, why du show its 0 blocks.
If it should be 0 blocks then why Java show up some bytes used by an empty directory?
$ mkdir empty_directory
$ du -h empty_directory/
0B empty_directory/
$ du empty_directory
0 empty_directory
File f = new File("/test/empty_directory");
if (f.exists() && f.isDirectory()) {
System.out.println(f.length());
}
68
2> for a same no empty file, the size show by linux command du is still not same as that of File.length() in java.
Is the reason only from the difference units: the blocks used by du and the bytes used by File.length()?
$ du -h oneline.txt
4.0K oneline.txt
$ du oneline.txt
8 oneline.txt
$ ls -s oneline.txt
8 oneline.txt
-s Display the number of file system blocks actually used by each file, in units of 512 bytes, where partial units are rounded up to the next integer value. If the output is to a terminal, a total sum for all the file sizes is output on a line before the listing. The environment variable BLOCKSIZE overrides the unit size of 512 bytes.
File f = new File("/test/oneline.txt");
if (f.exists() && f.isFile()) {
System.out.println(f.length());
}
26
confused. will you please give some help on this?