Java BufferedReader Read Line readLine(String filename, String encoding)

Here you can find the source of readLine(String filename, String encoding)

Description

read Line

License

Open Source License

Declaration

public static List<String> readLine(String filename, String encoding) 

Method Source Code

//package com.java2s;
/*===============================================================================
 * Copyright (c) 2010-2012 University of Massachusetts.  All Rights Reserved.
 *
 * Use of the RankLib package is subject to the terms of the software license set 
 * forth in the LICENSE file included with this software, and also available at
 * http://people.cs.umass.edu/~vdang/ranklib_license.html
 *===============================================================================
 *///from   w w w  .  jav a 2s . c  o  m

import java.io.BufferedReader;

import java.io.FileInputStream;

import java.io.InputStreamReader;

import java.util.ArrayList;
import java.util.List;

public class Main {
    public static List<String> readLine(String filename, String encoding) {
        List<String> lines = new ArrayList<String>();
        try {
            String content = "";
            BufferedReader in = new BufferedReader(new InputStreamReader(new FileInputStream(filename), encoding));

            while ((content = in.readLine()) != null) {
                content = content.trim();
                if (content.length() == 0)
                    continue;
                lines.add(content);
            }
            in.close();
        } catch (Exception ex) {
            System.out.println(ex.toString());
        }
        return lines;
    }
}

Related

  1. readLine(InputStream input)
  2. readLine(RandomAccessFile wiki)
  3. readLine(Reader rd)
  4. readLine(String fileName)
  5. readLine(String fileName)
  6. readLine(String filepath)
  7. readLine(String filePathAndName, String encoding)
  8. readLine(String fmt, Object... args)
  9. readLine(String path)