< prev index next >
src/java.base/share/classes/java/nio/file/Files.java
Print this page
@@ -41,11 +41,13 @@
import java.nio.channels.FileChannel;
import java.nio.channels.SeekableByteChannel;
import java.nio.charset.Charset;
import java.nio.charset.CharsetDecoder;
import java.nio.charset.CharsetEncoder;
+import java.nio.charset.MalformedInputException;
import java.nio.charset.StandardCharsets;
+import java.nio.charset.UnmappableCharacterException;
import java.nio.file.attribute.BasicFileAttributeView;
import java.nio.file.attribute.BasicFileAttributes;
import java.nio.file.attribute.DosFileAttributes; // javadoc
import java.nio.file.attribute.FileAttribute;
import java.nio.file.attribute.FileAttributeView;
@@ -3280,10 +3282,14 @@
byte[] ba = readAllBytes(path);
try {
return JLA.newStringNoRepl(ba, cs);
} catch (IllegalArgumentException e) {
+ Throwable cause = e.getCause();
+ if (cause != null && cause instanceof MalformedInputException) {
+ throw (MalformedInputException)cause;
+ }
throw new IOException(e);
}
}
/**
@@ -3636,10 +3642,14 @@
try {
byte[] bytes = JLA.getBytesNoRepl(String.valueOf(csq), cs);
write(path, bytes, options);
} catch (IllegalArgumentException e) {
+ Throwable cause = e.getCause();
+ if (cause != null && cause instanceof UnmappableCharacterException) {
+ throw (UnmappableCharacterException)cause;
+ }
throw new IOException(e);
}
return path;
}
< prev index next >