Here you can find the source of fileToString(File f)
Parameter | Description |
---|---|
f | a parameter |
Parameter | Description |
---|---|
FileNotFoundException | an exception |
public static String fileToString(File f) throws FileNotFoundException
//package com.java2s; //it under the terms of the GNU Lesser General Public License as import java.io.*; import java.util.*; public class Main { /**// ww w .ja v a 2 s . c om * Reads in a File and dumps it into a String. * * @param f * @return a String containing all text from f. * @throws FileNotFoundException */ public static String fileToString(File f) throws FileNotFoundException { Scanner s = new Scanner(f); StringBuilder sb = new StringBuilder(); while (s.hasNextLine()) { sb.append(s.nextLine() + '\n'); } s.close(); return sb.toString(); } }