Java InputStreamReader Read readFileIntoLinesOfLongs(File file)

Here you can find the source of readFileIntoLinesOfLongs(File file)

Description

read File Into Lines Of Longs

License

BSD License

Declaration

public static List<Long> readFileIntoLinesOfLongs(File file) 

Method Source Code

//package com.java2s;
/**/*from w  w w. j ava  2s.  co m*/
 * <p>
 * Utilities for manipulating Paths, Files, Directories, etc.
 * </p>
 * <p>
 * <span class="BSDLicense"> This software is distributed under the <a
 * href="http://hci.stanford.edu/research/copyright.txt">BSD License</a>.</span>
 * </p>
 * 
 * @author <a href="http://graphics.stanford.edu/~ronyeh">Ron B Yeh</a> (ronyeh(AT)cs.stanford.edu)
 */

import java.io.BufferedReader;

import java.io.File;

import java.io.FileInputStream;
import java.io.FileNotFoundException;

import java.io.IOException;

import java.io.InputStreamReader;

import java.util.ArrayList;

import java.util.List;

public class Main {
    public static List<Long> readFileIntoLinesOfLongs(File file) {
        List<String> lines = readFileIntoLines(file);
        List<Long> dest = new ArrayList<Long>();
        for (String s : lines) {
            dest.add(Long.parseLong(s));
        }
        return dest;
    }

    /**
     * Reads a file into a list of Strings
     * 
     * @param file
     * @return
     * @throws IOException
     */
    public static List<String> readFileIntoLines(File file) {
        List<String> lines = new ArrayList<String>();
        try {
            FileInputStream fis = new FileInputStream(file);
            BufferedReader read = new BufferedReader(new InputStreamReader(fis));

            String line;
            while ((line = read.readLine()) != null) {
                lines.add(line);
            }
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return lines;
    }
}

Related

  1. readFileFromClassPath(String file)
  2. readFileFromDisk(String filepath)
  3. readFileFromResource(@SuppressWarnings("rawtypes") Class refClass, String filePath)
  4. readFileFromResource(String filename)
  5. readFileIntoLines(File file)
  6. readFileLineByLine(final File filePath)
  7. readFileList(File file)
  8. readFileOneLine(String filename, String keyInLine)
  9. readFileOrResource(String source)