Popular Feed

Read a text file and return data in array list using java

public List<String> readFile(String filePath) {

List<String> inputList= new ArrayList<>();

File fileName=new File(filePath);

BufferedReader br=null;

String inputscript=null;

try {

br = new BufferedReader(new FileReader(fileName));

while ((inputscript = br.readLine()) != null) {

inputList.add(inputscript);

}

} catch (IOException e) {

// TODO Auto-generated catch block

e.printStackTrace();

}

finally {

try {

br.close();

} catch (IOException e) {

// TODO Auto-generated catch block

e.printStackTrace();

}

}

return inputList;



No comments: