Here you can find the source of readFile(File file)
Parameter | Description |
---|---|
file | File for txt document |
public static String readFile(File file)
//package com.java2s; //License from project: Apache License import java.io.BufferedReader; import java.io.File; import java.io.FileReader; import java.io.IOException; public class Main { /****//from ww w. jav a 2s. co m * create a String from given File * * @param file * File for txt document * @return Document */ public static String readFile(File file) { StringBuffer buf = new StringBuffer(); BufferedReader reader = null; try { reader = new BufferedReader(new FileReader(file)); String tempString = null; int line = 1; while ((tempString = reader.readLine()) != null) { buf.append(tempString); line++; } reader.close(); } catch (IOException e) { e.printStackTrace(); } finally { if (reader != null) { try { reader.close(); } catch (IOException e1) { } } } return buf.toString(); } }