java.nio.file.Files.isReadable() returns false on readable file
Victor Ott
victor.ott at gmail.com
Mon Jul 16 09:19:17 PDT 2012
Hello,
I've searched for similar issues and have found this thread int nio-dev
mailing list: "java.nio.file.Files.isReadable() slow on Windows 7" (
http://mail.openjdk.java.net/pipermail/nio-dev/2012-May/001666.html or
http://markmail.org/thread/ytjr6dwrxwxku2r4 ), but am asking this on
nio-discuss because ... maybe I'm not seeing the obvious.
Besides noticing that the first call to Files.isReadable() is indeed slow
(only the first one, not subsequent calls), I have another issue:
Files.isReadable() fails an a obviously readable file. See below my example
code.
Here the output:
file: c:\temp\dummyfile.txt
freshly read: ABC
File.canRead(): true
Files.isReadable(): false
WinXP x32, JDK7u5 x32, NTFS file system. (And yes, I do have local admin
rights).
Thanks in advance,
Victor
package tst;
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.io.Writer;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
public class FilesIsReadableTest {
public static void main(String[] args) throws IOException {
final Path rootDirectory = Paths.get("c:/temp");
final Path file = Paths.get(rootDirectory.toString(),
"dummyfile.txt");
Files.deleteIfExists(file);
Files.createFile(file);
System.out.println("file: " + file);
try (Writer o = new FileWriter(file.toFile())) {
o.write("ABC");
}
try (BufferedReader r = new BufferedReader(new
FileReader(file.toFile()))) {
System.out.println("freshly read: " + r.readLine());
}
System.out.println("File.canRead(): " +
file.toFile().canRead());
System.out.println("Files.isReadable(): " + Files.isReadable(file));
}
}
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.openjdk.java.net/pipermail/nio-discuss/attachments/20120716/81504e1b/attachment.html
More information about the nio-discuss
mailing list