List of utility methods to do UTF8 File Read
BufferedReader | getBufferedUTF8Reader(InputStream inputStream) Creates a BufferedReader the UTF-8-encoded InputStream return new BufferedReader(new InputStreamReader(inputStream, Charset.forName("UTF-8"))); |
byte[] | getUtf8BytesFromFile(String fileName) get Utf Bytes From File InputStream inputStream = Thread.currentThread().getContextClassLoader().getResourceAsStream(fileName); Reader reader = new InputStreamReader(inputStream); StringBuffer stringBuffer = new StringBuffer(); char[] buffer = new char[4096]; int len; while ((len = reader.read(buffer)) > 0) { stringBuffer.append(buffer, 0, len); return stringBuffer.toString().getBytes("UTF-8"); |
Writer | getUtf8FileWriter(String file, boolean append) get Utf File Writer return new OutputStreamWriter(new FileOutputStream(file, append), "utf-8"); |
InputStreamReader | getUTF8InputStreamReader(InputStream stream) get UTF Input Stream Reader return getInputStreamReader(stream, StandardCharsets.UTF_8);
|
BufferedReader | getUTF8Reader(File f) get UTF Reader return new BufferedReader( new InputStreamReader(new FileInputStream(f), Charset.forName("UTF-8").newDecoder())); |
String | loadUTF8(File file) load UTF FileInputStream is = new FileInputStream(file); try { return loadUTF8(is); } finally { is.close(); |
Reader | makeUTF8Reader(InputStream inputStream) Constructs a new Reader based on the UTF-8 encoding. return new InputStreamReader(inputStream, UTF_8_CHARSET); |
InputStreamReader | newUtf8Reader(final InputStream in) new Utf Reader return new InputStreamReader(in, StandardCharsets.UTF_8); |
Reader | openFileReaderUTF8(File file) open File Reader UTF return openFileReader(file, "UTF-8"); |
List | readAllLines(File inputFile) read All Lines List<String> ret = new ArrayList<String>(); String line; BufferedReader br = null; try { InputStream fis = new FileInputStream(inputFile); InputStreamReader isr = new InputStreamReader(fis, Charset.forName("UTF-8")); br = new BufferedReader(isr); while ((line = br.readLine()) != null) { ... |