Here you can find the source of readFile(File f)
Parameter | Description |
---|---|
f | File that should be read |
public static List<String> readFile(File f)
//package com.java2s; /*//from w w w . j a v a 2 s .c om * Copyright (c) 2010-2012 Research In Motion Limited. All rights reserved. * * This program and the accompanying materials are made available * under the terms of the Eclipse Public License, Version 1.0, * which accompanies this distribution and is available at * * http://www.eclipse.org/legal/epl-v10.html * */ import java.io.BufferedReader; import java.io.File; import java.io.FileNotFoundException; import java.io.FileReader; import java.io.IOException; import java.util.ArrayList; import java.util.List; public class Main { /** * Reads the content of a file and returns an ArrayList with the data * * @param f * File that should be read * @return ArrayList of data */ public static List<String> readFile(File f) { List<String> data = new ArrayList<String>(); try { BufferedReader br = new BufferedReader(new FileReader(f)); while (br.ready()) { data.add(br.readLine()); } return data; } catch (FileNotFoundException e) { return null; } catch (IOException e) { return null; } } }