1. 程式人生 > >【將檔案中字串賦值到 ArrayList 中】

【將檔案中字串賦值到 ArrayList 中】

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 {

    public
static 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); } } }