【把 ArrayList 集合中的字符串内容写到文本文件中】

package com.companyname.common.test;

import java.io.BufferedWriter;
import java.io.FileWriter;
import java.io.IOException;
import java.util.ArrayList;

/**
 * @Description 把 ArrayList 集合中的字符串内容写到文本文件中
 * @Author Created by shusheng.
 * @Email shusheng@yiji.com
 * @Date 2018/12/2
 */
public class ArrayListToFileDemo {

    public static void main(String[] args) throws IOException {

        ArrayList<String> array = new ArrayList<String>();
        array.add("hello");
        array.add("world");
        array.add("java");

        BufferedWriter bw = new BufferedWriter(new FileWriter("a.txt"));

        for(String s:array){
            bw.write(s);
            bw.newLine();
            bw.flush();
        }

        bw.close();
    }

}

 

posted @ 2018-12-08 10:36  书丶生  阅读(813)  评论(0编辑  收藏  举报