List of utility methods to do Text File Read by Charset
String | readAll(InputStream inputStream, Charset charset) Read all stream byte data into String return readAll(inputStream, charset.name());
|
String | readAll(InputStream inputStream, Charset encoding) read All try (Reader reader = new InputStreamReader(inputStream, encoding)) { return readAll(reader); |
String | readAllLines(File file, Charset cs, String newLineDelimiter) read All Lines final StringBuilder sb = new StringBuilder(); try (InputStream in = new FileInputStream(file); final InputStreamReader reader = new InputStreamReader(in, cs); final BufferedReader buffer = new BufferedReader(reader)) { String line; while ((line = buffer.readLine()) != null) { sb.append(line); if (newLineDelimiter != null) { ... |
List | readAllLines(InputStream stream, Charset charset) Reads all lines using a BufferedReader and the given charset. if (stream == null) { return Collections.emptyList(); try (BufferedReader reader = new BufferedReader(new InputStreamReader(stream, charset))) { return reader.lines().collect(Collectors.toList()); } catch (IOException e) { throw new IOException("An error occurred during reading lines.", e); |
List | readAllLines(Path path, Charset cs) read All Lines try { return Files.readAllLines(path, cs); } catch (IOException e) { throw new RuntimeException(e); |
String | readAllText(File file, Charset charset) read All Text try { return readAllText(new FileInputStream(file), charset); } catch (FileNotFoundException e) { return null; |
String | readAllText(File file, Charset charset) read All Text try { StringBuilder sb = new StringBuilder(); LineNumberReader reader = new LineNumberReader(new FileReader(file)); String line = null; while ((line = reader.readLine()) != null) { sb.append(line); return sb.toString(); ... |
String | readAsString(InputStream in, Charset charset) read As String return new String(readAsBytes(in), charset); |
String | readAsString(InputStream is, CharsetDecoder decoder) read As String InputStreamReader reader = new InputStreamReader(is, decoder); return readAsString(reader); |
char[] | readCharsWithEncoding(File file, Charset charset) read Chars With Encoding InputStreamReader isr = new InputStreamReader(new FileInputStream(file), charset); BufferedReader br = new BufferedReader(isr); char[] chars = new char[(int) file.length()]; br.read(chars); isr.close(); br.close(); return chars; |