List of utility methods to do InputStreamReader Read
List | readFileCharacters(File file, boolean fix) Reads and returns every character in the specified file, except line breaks. final InputStream input_stream = new FileInputStream(file); final BufferedReader buffered_reader = new BufferedReader(new InputStreamReader(input_stream)); final List<Character> character_list = new ArrayList<>(); String line; try { while ((line = buffered_reader.readLine()) != null) { if (fix) line = line.replace('\t', ' '); ... |
String | readFileData(File file) read File Data StringBuilder sb = new StringBuilder(); FileInputStream in = null; BufferedReader br = null; try { in = new FileInputStream(file); br = new BufferedReader(new InputStreamReader(in)); String data = null; while ((data = br.readLine()) != null) { ... |
List | readFileData(String directoryLocation, String fileName) read File Data FileInputStream fstream = null; List<String> contents = null; try { fstream = new FileInputStream(directoryLocation.concat(fileName)); DataInputStream in = new DataInputStream(fstream); BufferedReader br = new BufferedReader(new InputStreamReader(in)); String strLine; contents = new ArrayList<String>(); ... |
String | readFileFromClassPath(String file) Read file from class path InputStream is = ClassLoader.getSystemResourceAsStream(file); BufferedReader br = new BufferedReader(new InputStreamReader(is)); String content = ""; String line; try { while ((line = br.readLine()) != null) content = content + line + "\n"; } catch (IOException e) { ... |
String | readFileFromDisk(String filepath) read File From Disk FileInputStream fis = null; BufferedReader br = null; StringBuffer sb = new StringBuffer(); String temp = ""; try { fis = new FileInputStream(filepath); br = new BufferedReader(new InputStreamReader(fis, "utf-8")); while ((temp = br.readLine()) != null) { ... |
String | readFileFromResource(@SuppressWarnings("rawtypes") Class refClass, String filePath) Read a file from a resource rather than from a file StringBuffer fileData = new StringBuffer(1000); BufferedReader reader = new BufferedReader(new InputStreamReader(refClass.getResourceAsStream(filePath))); char[] buf = new char[1024]; int numRead = 0; while ((numRead = reader.read(buf)) != -1) { String readData = String.valueOf(buf, 0, numRead); fileData.append(readData); buf = new char[1024]; ... |
String | readFileFromResource(String filename) read File From Resource try { InputStream is = Thread.currentThread().getContextClassLoader().getResourceAsStream(filename); BufferedReader br = new BufferedReader(new InputStreamReader(is)); StringBuilder stringBuilder = new StringBuilder(); String line; while ((line = br.readLine()) != null) { stringBuilder.append(line); br.close(); return stringBuilder.toString(); } catch (Exception e) { e.printStackTrace(); return null; |
List | readFileIntoLines(File file) Reads a file into a list of Strings List<String> lines = new ArrayList<String>(); try { FileInputStream fis = new FileInputStream(file); BufferedReader read = new BufferedReader(new InputStreamReader(fis)); String line; while ((line = read.readLine()) != null) { lines.add(line); } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); return lines; |
List | readFileIntoLinesOfLongs(File file) read File Into Lines Of Longs List<String> lines = readFileIntoLines(file); List<Long> dest = new ArrayList<Long>(); for (String s : lines) { dest.add(Long.parseLong(s)); return dest; |
Iterator | readFileLineByLine(final File filePath) read File Line By Line return new Iterator<String>() { InputStream fstream = new FileInputStream(filePath); if (filePath.getName().endsWith(".gz")) { fstream = new GZIPInputStream(fstream); DataInputStream in = new DataInputStream(fstream); ... |