Java BufferedReader Read readFileToList(String path, String split)

Here you can find the source of readFileToList(String path, String split)

Description

Reads contents of files and splits it into an array by List object

License

Apache License

Parameter

Parameter Description
path The directory or path to the text file to be read
split Regex split; returns array by split

Return

tmp

Declaration


public static List<String> readFileToList(String path, String split) 

Method Source Code


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

import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

public class Main {
    /**//from w w  w  .ja  va2s . c  om
     * 
     * Reads contents of files and splits it into an array by List object
     * 
     * @see List<?>
     * 
     * @param path The directory or path to the text file to be read
     * @param split Regex split; returns array by split
     * @return tmp
     */

    public static List<String> readFileToList(String path, String split) {
        List<String> tmp = new ArrayList<String>();
        String[] array = readFile(path).split(split);

        for (int i = 0; i < array.length; i++) {
            tmp.add(array[i]);
        }

        return tmp;
    }

    /**
     * 
     * Reads file and stores into a string and returns it in one method
     * 
     * @see BufferedReader
     * 
     * @param path The directory or path to the text file
     * @return str
     */
    public static String readFile(String path) {
        String str = "";
        try {
            BufferedReader reader = new BufferedReader(new FileReader("path"));

            String tmp = "";

            while ((tmp = reader.readLine()) != null)
                str += "";

            reader.close();
        } catch (IOException e) {
            e.printStackTrace();
        }

        return str;
    }
}

Related

  1. readFileGdeHash(File gdeFile, ArrayList name, ArrayList seq)
  2. readFilePathToString(String filePath)
  3. readFileToHashMap(String filePath, String separator, boolean valueFirst)
  4. readFileToHashMap(String filePath, String separator, boolean valueFirst)
  5. readFileToList(String fileName, List list)
  6. readFileToListOfStrings(File file)
  7. readFileValue(File file)
  8. readFileWithoutLineBreak(String filename, boolean skipEmptyLine)