Java BufferedReader Read readFileAsList(String filename, String splitter)

Here you can find the source of readFileAsList(String filename, String splitter)

Description

read File As List

License

Apache License

Declaration

public static List<String> readFileAsList(String filename, String splitter) throws IOException 

Method Source Code


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

import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;

import java.io.IOException;
import java.util.ArrayList;

import java.util.List;

public class Main {
    public final static String newline = System.getProperty("line.separator");

    public static List<String> readFileAsList(String filename, String splitter) throws IOException {
        List<String> list = new ArrayList<String>();

        File file = new File(filename);
        FileReader freader = new FileReader(file);
        StringBuilder builder = new StringBuilder();
        try (BufferedReader breader = new BufferedReader(freader)) {
            String line = breader.readLine();
            while (null != line) {
                builder.append(line);// ww w .  j  ava2s. c o m
                builder.append(newline);
                line = breader.readLine();
            }
        }
        String fileContent = builder.toString();
        String[] segs = fileContent.split(splitter);
        for (String seg : segs) {
            list.add(seg.trim());
        }
        return list;
    }
}

Related

  1. readFile(String xmlFile)
  2. readFileAsHash(File file)
  3. readFileAsLines(File fileLocation)
  4. readFileAsLines(String aFile)
  5. readFileAsList(final String filename)
  6. readFileAsListOfString(String fileName, String splitBy)
  7. readFileAsListOfStrings(String filename)
  8. readFileAsListOfStrings(String filename)
  9. readFileAsText(String path)