List of utility methods to do Text File Read
String | getFileContentAsString(String path) get File Content As String BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream(path), "UTF-8")); String data = new String(); try { String line; while ((line = br.readLine()) != null) { data = data.concat(line); } finally { ... |
String | getFileContents(Reader reader) get File Contents StringBuilder sb = new StringBuilder(); for (int c = reader.read(); c >= 0; c = reader.read()) { sb.append((char) c); return sb.toString(); |
String | getFileContents(String filePath) get File Contents try (InputStream stream = new FileInputStream(filePath)) { return getTextStreamContents(stream); } catch (final IOException ex) { throw new IllegalArgumentException(ex); |
String | getFileContents(String filePath) get File Contents File file = new File(filePath); Scanner scanner = new Scanner(file); if (!scanner.hasNext()) { return null; return scanner.useDelimiter("\\Z").next(); |
List | getFileContents(String filePath) Reads the contents of the file at the given path, returning it line-by- line in a List .
File file = new File(filePath); if (file.exists() && !file.isDirectory()) { try (Scanner fileScanner = new Scanner(file)) { List<String> lines = new ArrayList<>(); while (fileScanner.hasNextLine()) { lines.add(fileScanner.nextLine()); fileScanner.close(); ... |
String | getFileContents(String filePath) Fetch the entire contents of a text file, and return it in a String. StringBuffer contents = new StringBuffer(); BufferedReader input = null; input = new BufferedReader(new FileReader(new File(filePath))); String line = null; while ((line = input.readLine()) != null) { contents.append(line); contents.append(System.getProperty("line.separator")); return contents.toString(); |
Vector | getFileContents(String path) get File Contents Vector<String> words = new Vector<String>(); try { FileInputStream fstream = new FileInputStream(path); DataInputStream in = new DataInputStream(fstream); BufferedReader br = new BufferedReader(new InputStreamReader(in)); String strLine; while ((strLine = br.readLine()) != null) { words.add(strLine); ... |
String | getFileContents(String pathToFile) FileUtils.getFileContents() Returns the content of a file as a String BufferedReader br = null; String content = ""; try { String sCurrentLine; br = new BufferedReader(new FileReader(pathToFile)); while ((sCurrentLine = br.readLine()) != null) { content += sCurrentLine + "\r\n"; } finally { if (br != null) br.close(); return content; |
String | getFileContents(String pFileName) Method that returns the file contents String fileContents = null; InputStream is = new FileInputStream(pFileName); BufferedReader reader = new BufferedReader(new InputStreamReader(is)); StringBuffer xml = new StringBuffer(); String aLine = null; while ((aLine = reader.readLine()) != null) { xml.append(aLine); xml.append("\n"); ... |
String | loadAsString(String location) load As String final StringBuilder result = new StringBuilder(); try { final BufferedReader reader = new BufferedReader(new FileReader(location)); String buffer = ""; while ((buffer = reader.readLine()) != null) { result.append(buffer).append("\n"); reader.close(); ... |