Java BufferedReader Read readFile(String directory)

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

Description

read File

License

Open Source License

Declaration

public static String readFile(String directory) 

Method Source Code

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

import java.io.*;

public class Main {
    public static String readFile(String directory) {

        String path = "", file;
        String[] S = directory.split("/");
        for (int i = 0; i < S.length - 1; i++)
            path += (S[i] + "/");
        file = S[S.length - 1];/*www.ja  v  a 2 s  . com*/

        File dir = new File(path);
        File arq = new File(dir, file);
        String text = "";

        try {

            FileReader reader = new FileReader(arq);
            BufferedReader reading = new BufferedReader(reader);
            String line = "";
            while ((line = reading.readLine()) != null)
                text += line;
            reader.close();
            reading.close();

        } catch (IOException e) {

            e.printStackTrace();

        }

        return text;
    }
}

Related

  1. readFile(final String pFile)
  2. readFile(List fieldNames, String filename)
  3. readFile(Reader reader)
  4. readFile(String absoluteFilePath)
  5. readFile(String aFileName)
  6. readFile(String directory, String fileName)
  7. readFile(String file)
  8. readFile(String file)
  9. readFile(String file)