public static void main(String[] args) {
// 文件夾路徑
String path = "E:\\eclipse work\\ImageUtil\\src\\scan.txt";
List<String> scanListPath = readFile02(path);
}
/**
* 讀取一個文本 一行一行讀取
*
* @param path
* @return
* @throws IOException
*/
public static List<String> readFile02(String path) throws IOException {
// 使用一個字符串集合來存儲文本中的路徑 ,也可用String []數組
List<String> list = new ArrayList<String>();
FileInputStream fis = new FileInputStream(path);
// 防止路徑亂碼 如果utf-8 亂碼 改GBK eclipse里創建的txt 用UTF-8,在電腦上自己創建的txt 用GBK
InputStreamReader isr = new InputStreamReader(fis, "UTF-8");
BufferedReader br = new BufferedReader(isr);
String line = "";
while ((line = br.readLine()) != null) {
// 如果 t x t文件里的路徑 不包含---字符串 這里是對里面的內容進行一個篩選
if (line.lastIndexOf("---") < 0) {
list.add(line);
}
}
br.close();
isr.close();
fis.close();
return list;
}