Java File to String readFileAsString(String path)

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

Description

read File As String

License

Apache License

Declaration

public static List<String> readFileAsString(String path) throws Exception 

Method Source Code


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

import java.io.*;
import java.util.ArrayList;

import java.util.List;

public class Main {
    public static List<String> readFileAsString(String path) throws Exception {
        BufferedReader reader = new BufferedReader(new InputStreamReader(new FileInputStream(new File(path))));

        try {//  w ww  .  jav  a  2 s  .  c  o  m
            List<String> list = new ArrayList<>();
            String line = reader.readLine();
            while (line != null) {
                list.add(line);
                line = reader.readLine();
            }
            return list;
        } finally {
            if (reader != null) {
                reader.close();
            }
        }
    }
}

Related

  1. readFileAsString(String filePathname)
  2. readFileAsString(String fname)
  3. readFileAsString(String fname)
  4. readFileAsString(String fpath)
  5. readFileAsString(String path)
  6. readFileAsString(String path)
  7. readFileAsString(String path)