Java Text File Load loadText(File f)

Here you can find the source of loadText(File f)

Description

load Text

License

Open Source License

Declaration

public static String loadText(File f) throws IOException 

Method Source Code


//package com.java2s;
//    it under the terms of the GNU General Public License as published by

import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;

import java.io.IOException;
import java.io.InputStreamReader;

import java.io.Reader;

public class Main {
    public static String loadText(File f) throws IOException {

        return loadReader(new InputStreamReader(new FileInputStream(f)));
    }//from ww w. j a  va 2  s.c o m

    public static String loadReader(Reader stream) throws IOException {
        BufferedReader r = null;
        StringBuilder text = new StringBuilder();
        try {
            r = new BufferedReader(stream);

            String line = null;
            while ((line = r.readLine()) != null) {
                text.append(line);
                text.append(System.getProperty("line.separator"));
            }
        } finally {
            if (r != null) {
                r.close();
            }
        }
        return text.toString();
    }
}

Related

  1. loadText(File file)
  2. loadText(File file)
  3. loadText(File file)
  4. loadText(File file, int bufsize)