【把 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 [email protected]
 * @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();
    }

}

猜你喜欢

转载自www.cnblogs.com/zuixinxian/p/10086902.html