Skip to content
Advertisement

Tag: nio2

Different results reading file with Files.newBufferedReader() and constructing readers directly

It seems that Files.newBufferedReader() is more strict about UTF-8 than the naive alternative. If I create a file with a single byte 128—so, not a valid UTF-8 character—it will happily be read if I construct an BufferedReader on an InputStreamReader on the result of Files.newInputStream(), but with Files.newBufferedReader() an exception is thrown. This code has this result: Is this documented?

java.nio.file.Path for a classpath resource

Is there an API to get a classpath resource (e.g. what I’d get from Class.getResource(String)) as a java.nio.file.Path? Ideally, I’d like to use the fancy new Path APIs with classpath resources. Answer This one works for me:

Advertisement