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.BufferedReader;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {
    public static String readFile(String file) {
        StringBuffer buffer = new StringBuffer();
        try {/* w w w.  j  a v  a2  s .  com*/
            BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream(file), "UTF-8"));
            while (br.ready()) {
                buffer.append(br.readLine()).append("\n");
            }
            br.close();
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }

        return buffer.toString();
    }
}

Related

  1. readFile(InputStream stream, StringBuilder builder)
  2. readFile(Reader simpleReader)
  3. readFile(String aFile)
  4. readFile(String f)
  5. readFile(String f, String delim)
  6. readFile(String file)
  7. readFile(String file)
  8. readFile(String file)
  9. readFile(String file)