3 * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved.
5 * This program and the accompanying materials are made available under the
6 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
7 * and is available at http://www.eclipse.org/legal/epl-v10.html
10 package org.opendaylight.controller.sal.utils;
12 import java.io.BufferedReader;
13 import java.io.DataInputStream;
15 import java.io.FileInputStream;
16 import java.io.FileNotFoundException;
17 import java.io.IOException;
18 import java.io.InputStreamReader;
19 import java.util.ArrayList;
22 * Convenience object for reading from file
27 public class ReadFromFile {
28 private FileInputStream fileStream;
29 private File filePointer;
31 public ReadFromFile(String fileName) throws FileNotFoundException {
32 fileStream = new FileInputStream(fileName);
33 filePointer = new File(fileName); //needed to allow file deletion
36 public ArrayList<String> readFile() throws IOException {
37 DataInputStream dataInput = new DataInputStream(this.fileStream);
38 BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(dataInput));
40 ArrayList<String> lineList = new ArrayList<String>();
42 while ((line = bufferedReader.readLine()) != null) {
45 bufferedReader.close();
51 public boolean delete() {
52 if (filePointer == null) {
55 return filePointer.delete();