List of utility methods to do Text File Read by Encode
String | getFileContent(File file, String charset) get File Content StringBuffer sb = new StringBuffer(); try { BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream(file), charset)); String line = br.readLine(); while (line != null) { sb.append(line).append("\n\r"); line = br.readLine(); br.close(); return sb.toString(); } catch (Exception e) { return null; |
String | getFileContent(File file, String charsetName) get File Content if (file == null) return null; BufferedReader bf = new BufferedReader(new InputStreamReader(new FileInputStream(file), charsetName)); String content; StringBuilder sb = new StringBuilder(); while (true) { content = bf.readLine(); if (content == null) { ... |
String | getFileContent(FileInputStream fis, String encoding) get File Content BufferedReader br = new BufferedReader(new InputStreamReader(fis, encoding)); StringBuilder sb = new StringBuilder(); String line; while ((line = br.readLine()) != null) { sb.append(line); sb.append('\n'); return sb.toString(); ... |
String | getFileContent(InputStream is, String encoding) get File Content BufferedReader buff = new BufferedReader(new InputStreamReader(is, encoding)); String content = getContent(buff); buff.close(); return content; |
String | getFileContentAsString(File file, String encoding) Copies the contents of the given file to a string. FileInputStream fis = new FileInputStream(file); return getStreamAsString(fis, encoding); |
String | getFileContentAsString(File file, String encoding) Get the content (as string) of the given file. return new String(getFileContentAsBytes(file), encoding); |
String | getFileContentAsString(File file, String encoding) get File Content As String FileInputStream is = new FileInputStream(file); return new String(getStreamContentAsBytes(is), encoding); |
String | getFileContentAsString(String filePath, String fileEncoding) get File Content As String StringBuilder text = new StringBuilder(); String newLine = System.getProperty("line.separator"); try (Scanner scanner = new Scanner(new FileInputStream(filePath), fileEncoding)) { boolean isFirstLine = true; while (scanner.hasNextLine()) { if (isFirstLine) { text.append(scanner.nextLine()); isFirstLine = false; ... |
String | getFileContents(InputStream stream, String encoding) get File Contents StringBuilder contents = new StringBuilder(); char[] buffer = new char[2048]; int count; try { try (Reader in = new InputStreamReader(stream, encoding)) { while ((count = in.read(buffer)) > 0) { contents.append(buffer, 0, count); } catch (IOException ioe) { return null; return contents.toString(); |
String | getFileContents(String filename, String encoding) get File Contents return getContents(new FileInputStream(filename), encoding); |