Android Text File Read readFromFile(File file)

Here you can find the source of readFromFile(File file)

Description

read From File

License

Open Source License

Declaration

public static String readFromFile(File file) 

Method Source Code

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

import java.io.BufferedReader;
import java.io.File;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {
    public static String readFromFile(File file) {
        String result = "";

        try {//from w  w  w . j  av  a  2s  .  co m
            BufferedReader in = new BufferedReader(new InputStreamReader(
                    file.toURI().toURL().openStream()));
            String inputLine = in.readLine();
            while (inputLine != null) {
                result += inputLine + "\n";
                inputLine = in.readLine();
            }
            in.close();
        } catch (IOException e) {
            throw new RuntimeException(e);
        }

        return result;
    }
}

Related

  1. readFileAsString(File file)
  2. readFileAsString(File file, String charset)
  3. readFileAsString(String filename)
  4. readFileLineByLine(File file)
  5. readFree(File file)
  6. readFull(String path)
  7. readLines(String file)
  8. readStringFromClasspath(String path, Class c)
  9. readStringFromFile(String fileName)