List of utility methods to do Text File Read by Charset
Reader | reader(Class> baseClass, String resourceName, Charset charset) reader return new InputStreamReader(inputStream(baseClass, resourceName), charset); |
InputStreamReader | reader(InputStream in, String charsetName) reader InputStreamReader result; if (charsetName == null) { result = reader(in); } else { result = new InputStreamReader(in, Charset.forName(charsetName)); return result; |
BufferedReader | readerBuffered(final File file, final Charset charset) Open a buffered Reader , equivalent to: new BufferedReader(new InputStreamReader(new FileInputStream(file), charset)); BufferedReader reader = new BufferedReader(new InputStreamReader(new FileInputStream(file), charset)); return reader; |
String | readFile(Bundle bundle, String path, Charset cs) read File URL jsonUrl = bundle.getEntry(path); try (Scanner scanner = new Scanner(jsonUrl.openStream(), cs.name())) { scanner.useDelimiter("\\A"); if (scanner.hasNext()) { return scanner.next(); } else { throw new IOException("no content"); |
String | readFile(File f, Charset chst) read File FileInputStream fis = new FileInputStream(f); return readStream(fis, chst, f.length()); |
String | readFile(File file, Charset charset) read File FileInputStream stream = new FileInputStream(file); try { FileChannel fc = stream.getChannel(); MappedByteBuffer bb = fc.map(FileChannel.MapMode.READ_ONLY, 0, fc.size()); return charset.decode(bb).toString(); } finally { stream.close(); |
String | readFile(File file, Charset charset) read File InputStream is = new FileInputStream(file); ByteArrayOutputStream os = new ByteArrayOutputStream(); byte[] buffer = new byte[1024]; int read; try { while ((read = is.read(buffer)) != -1) { os.write(buffer, 0, read); os.flush(); ... |
String | readFile(File file, Charset cs) read File final FileInputStream stream = new FileInputStream(file); return readInputStream(stream, cs); |
String | readFile(File file, String charsetName) read File ByteArrayOutputStream baos = new ByteArrayOutputStream(); try (FileInputStream is = new FileInputStream(file)) { int length = 0; byte[] bytes = new byte[1024 * 4]; while ((length = is.read(bytes)) > 0) { baos.write(bytes, 0, length); } catch (FileNotFoundException e1) { ... |
String | readFile(File theFile, Charset theCharset) read File if (theCharset == null) { theCharset = Charset.defaultCharset(); Reader reader = new InputStreamReader(new FileInputStream(theFile), theCharset); return readFromReaderIntoString(reader); |