Here you can find the source of readFileToList(String path, String split)
Parameter | Description |
---|---|
path | The directory or path to the text file to be read |
split | Regex split; returns array by split |
public static List<String> readFileToList(String path, String split)
//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; } }