List of utility methods to do File to String
String | fileToString(String file) file To String try { File fileDir = new File(file); BufferedReader in = new BufferedReader(new InputStreamReader(new FileInputStream(fileDir), "UTF8")); String str, strOut = ""; while ((str = in.readLine()) != null) { str = str.replace("\uFEFF", ""); strOut += str + "\r\n"; in.close(); return strOut; catch (Exception e) { return ""; |
String | fileToString(String file) Read the contents of a file and place them in a string object. String contents = ""; File f = null; try { f = new File(file); if (f.exists()) { FileReader fr = null; try { fr = new FileReader(f); ... |
String | fileToString(String file, String encoding) file To String FileInputStream fis = new FileInputStream(file); ByteArrayOutputStream baos = new ByteArrayOutputStream(); byte[] buffer = new byte[10240]; int len = fis.read(buffer, 0, buffer.length); while (len > 0) { baos.write(buffer, 0, len); len = fis.read(buffer, 0, buffer.length); fis.close(); return baos.toString(encoding); |
String | FileToString(String file_name) File To String FileInputStream fis = new FileInputStream(file_name); return InputStreamToString(fis); |
String | fileToString(String filename) Returns the string representation of a given file. StringBuffer sb = new StringBuffer(); BufferedReader in = new BufferedReader(new FileReader(filename)); String str; while ((str = in.readLine()) != null) sb.append(str); in.close(); return sb.toString(); |
String | fileToString(String filename) file To String String result = null; DataInputStream in = null; try { byte[] buffer = new byte[(int) new File(filename).length()]; in = new DataInputStream(new FileInputStream(filename)); in.readFully(buffer); result = new String(buffer); in.close(); ... |
String | fileToString(String fileName) read the file content as a String with default character encoding. StringBuffer stringBuffer = new StringBuffer(); try { char[] buffer = new char[1024]; FileReader reader = new FileReader(fileName); int flag = -1; while ((flag = reader.read(buffer, 0, buffer.length)) != -1) { stringBuffer.append(buffer, 0, flag); } catch (FileNotFoundException e) { throw new IllegalArgumentException("[" + fileName + "] is not found."); } catch (IOException e) { throw new RuntimeException("Unexpected exception! caused by: " + e.getMessage(), e); return stringBuffer.toString(); |
String | fileToString(String fileName) file To String System.gc(); File file = new File(fileName); FileInputStream fis = new FileInputStream(file); BufferedReader dis = new BufferedReader(new InputStreamReader(fis)); StringBuffer buff = new StringBuffer(); String line = null; while ((line = dis.readLine()) != null) { buff.append(line); ... |
String | fileToString(String fileName) file To String String result = ""; try { FileInputStream file = new FileInputStream(fileName); byte[] b = new byte[file.available()]; file.read(b); file.close(); result = new String(b); } catch (FileNotFoundException e) { ... |
String | fileToString(String filename) file To String BufferedReader reader = new BufferedReader(new FileReader(filename)); String line = null; StringBuilder stringBuilder = new StringBuilder(); String ls = System.getProperty("line.separator"); while ((line = reader.readLine()) != null) { stringBuilder.append(line); stringBuilder.append(ls); return stringBuilder.toString(); |