Java InputStreamReader Read readFile(String file)

Here you can find the source of readFile(String file)

Description

read File

License

Apache License

Declaration

public static String readFile(String file) 

Method Source Code


//package com.java2s;
//License from project: Apache License 

import java.io.*;

public class Main {
    public static String readFile(String file) {
        FileReader rd = null;/*  ww w. j ava 2s.  co m*/
        try {
            rd = new FileReader(file);
        } catch (FileNotFoundException e) {

            e.printStackTrace();
        }
        BufferedReader br = new BufferedReader(rd);
        String text = new String();
        String statementString = new String();
        while (text != null) {
            try {
                text = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            if (text != null) {
                statementString = statementString + "\n" + text;
            }
        }
        return statementString;
    }

    public static String readFile(InputStream in) {
        InputStreamReader rd = new InputStreamReader(in);
        BufferedReader br = new BufferedReader(rd);
        String text = new String();
        String statementString = new String();
        while (text != null) {
            try {
                text = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            if (text != null) {
                statementString = statementString + "\n" + text;
            }
        }
        return statementString;
    }
}

Related

  1. readFile(String aFile)
  2. readFile(String f)
  3. readFile(String f, String delim)
  4. readFile(String file)
  5. readFile(String file)
  6. readFile(String file)
  7. readFile(String file)
  8. readFile(String file)
  9. readFile(String file, String charset)