Here you can find the source of readFileAddLine(String filePath, Object object)
Parameter | Description |
---|---|
filePath | a parameter |
object | a parameter |
public static List<Object> readFileAddLine(String filePath, Object object)
//package com.java2s; 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 { /**/*from w w w.j av a2 s . c o m*/ * get the file content convert to list . * * @param filePath * @param object * @return */ public static List<Object> readFileAddLine(String filePath, Object object) { if (filePath == null) { filePath = ""; } filePath = filePath.replaceAll(" ", ""); File file = new File(filePath); List<Object> list = new ArrayList<Object>(); if (file != null && file.getAbsolutePath() != null && !file.getAbsolutePath().equals("") && file.exists() && !file.isDirectory()) { BufferedReader bufferedReader = null; try { bufferedReader = new BufferedReader(new InputStreamReader(new FileInputStream(filePath), "utf-8")); String buffer = ""; int lineNumber = 1; while ((buffer = bufferedReader.readLine()) != null) { if (buffer.startsWith("==========")) { if (lineNumber < 10) { buffer = buffer.replaceFirst("=", "[ " + lineNumber + " ] "); } else if (lineNumber < 100) { buffer = buffer.replaceFirst("=", "[ " + lineNumber + " ] "); } else { buffer = buffer.replaceFirst("=", "[ " + lineNumber + " ] "); } lineNumber++; } list.add(buffer); } } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } finally { if (bufferedReader != null) { try { bufferedReader.close(); } catch (IOException e) { e.printStackTrace(); } } } if (list.size() == 0) { list.add(""); } return list; } else { return new ArrayList<Object>(); } } /** * determine if the file is directory . * * @param path * @return */ public static boolean isDirectory(String path) { return new File(path).isDirectory(); } }