【將檔案中字串賦值到 ArrayList 中】
阿新 • • 發佈:2018-12-08
package com.companyname.common.test; import java.io.BufferedReader; import java.io.FileReader; import java.io.IOException; import java.util.ArrayList; /** * @Description * @Author Created by shusheng. * @Email [email protected] * @Date 2018/12/2 */ public class FileToArrayListDemo { publicstatic void main(String[] args) throws IOException { BufferedReader br = new BufferedReader(new FileReader("a.txt")); ArrayList<String> array = new ArrayList<String>(); String line = null; while((line=br.readLine())!=null){ array.add(line); } br.close();for(String s:array){ System.out.println(s); } } }