Here you can find the source of fileToString(File f)
Parameter | Description |
---|---|
f | The file to read. |
public static String[] fileToString(File f)
//package com.java2s; import java.io.BufferedReader; import java.io.File; import java.io.FileReader; public class Main { /**/* w ww . jav a 2 s. c o m*/ * Read a file and return its contents as a string. * * @param f * The file to read. * @return The contents of the file as a string. */ public static String[] fileToString(File f) { try { StringBuffer buff = new StringBuffer(); BufferedReader in = new BufferedReader(new FileReader(f)); String line = null; while ((line = in.readLine()) != null) { buff.append(line); buff.append("\n"); } in.close(); return new String[] { buff.toString() }; } catch (Exception e) { throw new RuntimeException(e); } } }