List of utility methods to do Text File Read
String | readFile(String filePath) read File String result = new String(); FileInputStream fstream = new FileInputStream(filePath); DataInputStream in = new DataInputStream(fstream); BufferedReader br = new BufferedReader(new InputStreamReader(in)); String strLine; while ((strLine = br.readLine()) != null) { result += strLine + "\n"; in.close(); return result; |
String | readFile(String filename) Read a file into a string StringBuffer fileData = new StringBuffer(1000); BufferedReader reader = new BufferedReader(new FileReader(filename)); 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]; ... |
Set | readFile(String path) read File Set<String> set = new HashSet<String>(); try { BufferedReader br = new BufferedReader(new FileReader(path)); String line = null; while ((line = br.readLine()) != null) { set.add(line.trim()); br.close(); ... |
String | readFileAsString(File file) read File As String StringBuffer fStr = new StringBuffer(); try { InputStream is = new FileInputStream(file); if (file.getName().endsWith(".gz")) { is = new GZIPInputStream(is); BufferedReader reader = new BufferedReader( new InputStreamReader(is)); ... |
String | readFileAsString(File file, String charset) read File As String StringBuffer fStr = new StringBuffer(); try { InputStream is = new FileInputStream(file); if (file.getName().endsWith(".gz")) { is = new GZIPInputStream(is); BufferedReader reader = new BufferedReader( new InputStreamReader(is, charset)); ... |
String | readFileAsString(String filename) read File As String if (filename.startsWith(SERIALPREFIX)) { filename = serialFileName(filename); return readFileAsString(new File(filename)); |
ArrayDeque | readFileLineByLine(File file) Reads file and returns contents as ArrayDeque String filePath = file.getAbsolutePath(); FileInputStream fstream = new FileInputStream(filePath); DataInputStream in = new DataInputStream(fstream); BufferedReader br = new BufferedReader(new InputStreamReader(in)); String strLine; ArrayDeque<String> forReturn = new ArrayDeque<String>(); try { while ((strLine = br.readLine()) != null) { ... |
List | readFree(File file) read Free List<String> archive = new ArrayList<String>(); BufferedReader reader = new BufferedReader(new FileReader(file)); String s; do { s = reader.readLine(); if (s != null) { archive.add(s); } while (s != null); reader.close(); return archive; |
String | readFromFile(File file) read From File String result = ""; try { BufferedReader in = new BufferedReader(new InputStreamReader( file.toURI().toURL().openStream())); String inputLine = in.readLine(); while (inputLine != null) { result += inputLine + "\n"; inputLine = in.readLine(); ... |
String | readFull(String path) read Full return new String(Files.readAllBytes(Paths.get(path)), Charset.defaultCharset()); |