Here you can find the source of readFile(File filename)
Parameter | Description |
---|---|
filename | full path |
public static ArrayList<String> readFile(File filename)
//package com.java2s; /** /*from ww w . ja v a 2 s . co m*/ * IOUtils.java * * Copyright (c) 2006, JULIE Lab. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Common Public License v1.0 * * Author: tomanek * * Current version: 2.3 * Since version: 2.2 * * Creation date: Nov 1, 2006 * * Some more utils for JNET. * **/ import java.io.BufferedReader; import java.io.File; import java.io.FileReader; import java.io.IOException; import java.util.ArrayList; public class Main { /** * reads file into ArrayList. Each line is one element (String). * * @param filename * full path */ public static ArrayList<String> readFile(File filename) { ArrayList<String> lines = new ArrayList<String>(); try { BufferedReader br = new BufferedReader(new FileReader(filename)); try { String line = ""; while ((line = br.readLine()) != null) { lines.add(line); } br.close(); } catch (IOException e) { System.err.println("Read error " + e); } } catch (Exception e) { e.printStackTrace(); } return lines; } }