Even if the file is unreadable, Java can return file length()

I have a file that I have banned every license No one should be able to read documents, right? Actually, if I run

File f = new File("not_readable.pdf");
System.out.println(f.canRead())

I get

false

But if I call

File f = new File("not_readable.pdf");
System.out.println(f.length())

I get

455074

My understanding is that in order to get the file size, you must first open and read the file, but this result strongly indicates that I am wrong Does anyone know why? In addition, is there any way to prevent java file The size of the file accessed by the length () method?

I'm using Ubuntu 12.10

Solution

You are wrong: the length of the file is the file system metadata (at least for the file system running under Linux VFS) Anyone with read access to the directory can see all contained files and their sizes In order to prevent users from seeing the size of files, you must prevent them from seeing them completely, that is, the files are placed in a directory with permissions such as drwxr-x - if the user is not in the group associated with the directory, or drwx - if the user is in the group

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>