List of utility methods to do File to String
String | fileToString(File file, int max) file To String if (!file.exists() && file.canRead()) { throw new IllegalStateException("File " + file.getName() + " either does not exist or can not be read"); RandomAccessFile raf = new RandomAccessFile(file, "r"); if (raf.length() > max) { raf.close(); throw new IllegalStateException("File " + file.getName() + " is to large (>" + max); byte[] ba = new byte[(int) raf.length()]; raf.read(ba); raf.close(); return new String(ba); |
String | fileToString(File file, String charsetName) file To String FileInputStream in = new FileInputStream(file); try { return allToString(new InputStreamReader(in, charsetName)); } finally { in.close(); |
String | fileToString(File file, String charsetName) Transforms a file into a string. FileInputStream fileInputStream = null; try { try { fileInputStream = new FileInputStream(file); return streamToString(fileInputStream, charsetName); } finally { if (fileInputStream != null) { fileInputStream.close(); ... |
String[] | fileToString(File files[]) file To String String result[] = new String[files.length]; for (int i = 0; i < files.length; i++) { File file = files[i]; result[i] = file.getAbsolutePath(); return result; |
String | fileToString(final File file) file To String FileInputStream in = null; int size = 0; if (file.exists()) { in = new FileInputStream(file); size = (int) file.length(); try { int fRead = 0; ... |
String | fileToString(final File file, final String charsetName) Reads a file and returns it as a string. return streamToString(fileToStream(file), charsetName);
|
String | fileToString(final String filePath) Converts a file content to a string. byte[] buffer = new byte[(int) new File(filePath).length()]; BufferedInputStream f = null; try { f = new BufferedInputStream(new FileInputStream(filePath)); f.read(buffer); } finally { if (f != null) { f.close(); ... |
String | fileToString(InputStream file) Pasa todo el contenido de un fichero a una cadena String style = ""; Scanner sc = new Scanner(file); while (sc.hasNextLine()) { style += sc.nextLine() + "\n"; sc.close(); return style; |
String | fileToString(InputStream inputStream) file To String BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(inputStream)); return bufferedReader.lines().collect(Collectors.joining(System.lineSeparator())); |
String | fileToString(String file) Read a file into a String StringBuilder lines = new StringBuilder(); FileReader fileReader = null; BufferedReader bufferedReader = null; String line = null; try { fileReader = new FileReader(file); bufferedReader = new BufferedReader(fileReader); while ((line = bufferedReader.readLine()) != null) { ... |