List of utility methods to do File Read by Charset
String | getEOL(File file, Charset charset) get EOL String r = null; try (BufferedReader in = Files.newBufferedReader(file.toPath(), charset)) { while (true) { int ch = in.read(); if (ch < 0) { break; if (ch == '\n' || ch == '\r') { ... |
String | getFileContent(File file, String charsetName) get File Content if (file.isFile()) { FileInputStream inf = null; FileChannel inc = null; StringBuilder content = new StringBuilder(); try { inf = new FileInputStream(file); inc = inf.getChannel(); Charset charset = Charset.forName(charsetName); ... |
String | getFileContents(File file, String charset) Reads the contents of a text file. byte[] bytes = toByteArray(new FileInputStream(file), true); return new String(bytes, charset); |
Charset | getFileEncodingCharset() Returns the Charset which is equal to the "file.encoding" property. try { return Charset.forName(System.getProperty("file.encoding")); } catch (Throwable t) { return Charset.defaultCharset(); |
String | getFileText(File file, Charset charset) Reads a text file completely, using the specified encoding. BufferedReader br = null; try { if (!file.exists()) return ""; br = new BufferedReader(new InputStreamReader(new FileInputStream(file), charset)); StringWriter sw = new StringWriter(); int n; char[] cbuf = new char[1024]; ... |
int | getNumberOfNonEmptyLines(File file, Charset charset) get Number Of Non Empty Lines BufferedReader reader = new BufferedReader(new InputStreamReader(new FileInputStream(file), charset)); try { int count = 0; String line; while ((line = reader.readLine()) != null) if (!line.isEmpty()) ++count; return count; ... |
Charset | getPatchFileCharset() get Patch File Charset return Charset.forName("ISO-8859-1"); |
String | getPropertiesVaule(File file, String key, Charset charset) Gets properties vaule. if (file == null) { return null; if (charset == null) { charset = Charset.forName("ISO8859-1"); Properties properties = new Properties(); FileInputStream fis = null; ... |
String | getString(File file, Charset charset) Reads a file into a string. FileInputStream stream = new FileInputStream(file); try { FileChannel channel = stream.getChannel(); try { MappedByteBuffer buffer = channel.map(FileChannel.MapMode.READ_ONLY, 0, channel.size()); if (charset == null) charset = Charset.defaultCharset(); return charset.decode(buffer).toString(); ... |
List | getUncommentedLines(File file, Charset forName) get Uncommented Lines try { List<String> ids = Lists.newArrayList(); try (BufferedReader br = new BufferedReader(new FileReader(file))) { for (String line; (line = br.readLine()) != null;) { if (!line.trim().startsWith("#") && !line.trim().isEmpty()) ids.add(line.trim()); return ids; } catch (FileNotFoundException e) { throw new IOException(e); |