throw new RuntimeException("Encoding of the file '" + fileName + "' does not conform to " + charset + ".");
}
}
-
+
+ public static String readContentsWithCharset(String charset, String fileName) throws IOException {
+ try {
+ Charset cs = Charset.forName(charset);
+ return new String(Files.readAllBytes(Paths.get(fileName)), cs);
+ } catch(MalformedInputException e) {
+ throw new RuntimeException("Encoding of the file '" + fileName + "' does not conform to " + charset + ".");
+ }
+ }
+
public static void writeLines(String fileName, List<String> lines) throws IOException {
BufferedWriter writer = Files.newBufferedWriter(Paths.get(fileName), UTF8);
for(String line : lines) {
writer.write("\n");
writer.close();
}
+
}