Here you can find the source of fileToString(File file)
Parameter | Description |
---|---|
file | a parameter |
Parameter | Description |
---|---|
IOException | an exception |
public static String fileToString(File file) throws IOException
//package com.java2s; //License from project: Open Source License import java.io.BufferedReader; import java.io.File; import java.io.FileReader; import java.io.IOException; public class Main { /**/*from ww w .ja v a 2 s . c o m*/ * Reads a given file and stores its contents into a String * @param file * @return * @throws IOException */ public static String fileToString(File file) throws IOException { FileReader fr = new FileReader(file); BufferedReader br = new BufferedReader(fr); StringBuilder result = new StringBuilder(); String line = br.readLine(); while (line != null) { result.append(line + "\n"); line = br.readLine(); } fr.close(); br.close(); return result.toString(); } }