List of utility methods to do InputStreamReader Read
String | readFile(String path) Copied from http://stackoverflow.com/questions/326390/how-to-create-a-java-string-from-the-contents-of-a-file StringBuffer loadedContent = new StringBuffer(); try { InputStreamReader fileEditorInputReader = new InputStreamReader(new FileInputStream(path)); char[] buffer = new char[1024]; int bytesRead; do { bytesRead = fileEditorInputReader.read(buffer); if (bytesRead > 0) ... |
ArrayList | readFile(String path) read File ArrayList<String> result = new ArrayList<String>(); InputStreamReader isReader = new InputStreamReader(new FileInputStream(path), "UTF-8"); BufferedReader reader = new BufferedReader(isReader); String aline; while ((aline = reader.readLine()) != null) { result.add(aline); reader.close(); ... |
String | readFile(String path, String charset) read File FileInputStream fileStream = new FileInputStream(path); InputStreamReader inputStream = new InputStreamReader(fileStream, charset); try { StringBuilder sb = new StringBuilder(); int c; while ((c = inputStream.read()) != -1) { sb.append((char) c); return sb.toString(); } finally { inputStream.close(); fileStream.close(); |
String | readFile(ZipInputStream zin) read File final char[] buffer = new char[0x2048]; StringBuilder out = new StringBuilder(); Reader in = new InputStreamReader(zin, "US-ASCII"); int read; while ((read = in.read(buffer, 0, buffer.length)) > 0) { out.append(buffer, 0, read); String s = out.toString(); ... |
List | readFileAddLine(String filePath, Object object) get the file content convert to list . if (filePath == null) { filePath = ""; filePath = filePath.replaceAll(" ", ""); File file = new File(filePath); List<Object> list = new ArrayList<Object>(); if (file != null && file.getAbsolutePath() != null && !file.getAbsolutePath().equals("") && file.exists() && !file.isDirectory()) { ... |
String | readFileAll(File file, String charsetName) read File All return readInputStreamAll(new FileInputStream(file), charsetName); |
String[] | readFileAsArray(String path) read File As Array String[] result = new String[] {}; InputStream in = new FileInputStream(path); BufferedReader reader = new BufferedReader(new InputStreamReader(in, "UTF-8")); String line = ""; int i = 0; while ((line = reader.readLine()) != null) { line = line.trim(); if (line == null || "".equals(line)) { ... |
String | readFileAsJson(String path) Read json message from file. return readFileAsJson(new File(path)); |
List | readFileAsList(String path) read File As List List<String> ls = new ArrayList<String>(); InputStream in = new FileInputStream(path); BufferedReader reader = new BufferedReader(new InputStreamReader(in, "UTF-8")); String line = ""; while ((line = reader.readLine()) != null) { line = line.trim(); if (line == null || "".equals(line)) { continue; ... |
String | readFileByCharAsString(String path, String encode) read File By Char As String InputStream in = new FileInputStream(path); BufferedReader reader = new BufferedReader(new InputStreamReader(in, encode)); StringBuffer contentbuffer = new StringBuffer(); char[] temp = new char[1024]; int size = 0; while ((size = reader.read(temp, 0, 1024)) != -1) { String tempstr = new String(temp, 0, size); contentbuffer.append(tempstr); ... |