Java InputStreamReader Read readFile(String path)

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

Description

read File

License

Open Source License

Declaration

public static String readFile(String path) 

Method Source Code


//package com.java2s;
//License from project: Open Source License 

import java.io.*;

public class Main {
    public static String readFile(String path) {
        File myFile = new File(path);

        FileInputStream fIn;/*from   w w  w.j a  v  a2s  . co m*/
        try {
            if (!myFile.exists()) {
                if (myFile.getParentFile() != null) {
                    myFile.getParentFile().mkdirs();
                }
                myFile.createNewFile();
                return "";
            }
            fIn = new FileInputStream(myFile);
            BufferedReader myReader = new BufferedReader(new InputStreamReader(fIn));
            String aDataRow = "";
            String aBuffer = "";
            while ((aDataRow = myReader.readLine()) != null) {
                aBuffer += aDataRow;
            }
            myReader.close();
            return aBuffer;
        } catch (IOException e) {
            e.printStackTrace();
        }
        return "";
    }
}

Related

  1. readFile(String location)
  2. readFile(String name)
  3. readFile(String nomeFile)
  4. readFile(String p_filename)
  5. ReadFile(String Path)
  6. readFile(String path)
  7. readFile(String path)
  8. readFile(String path)
  9. readFile(String Path)