write file

public static void write(List<String> list)
    {
        String basePath = "/Users/Desktop/";
        String name = "20190611_user_new.txt";
        String path = basePath+name;
        try
        {
            File file=new File(path);
            if(!file.exists()){
                file.createNewFile();
            }
            FileOutputStream out=new FileOutputStream(file); //如果追加方式用true


            for (String line:list
                ) {
                StringBuffer sb=new StringBuffer();
                sb.append(line+"
");
                out.write(sb.toString().getBytes("utf-8"));//注意需要转换对应的字符集

            }

            out.close();
        }
        catch(IOException ex)
        {
            System.out.println(ex.getStackTrace());
        }
    }
原文地址:https://www.cnblogs.com/feelgood/p/11031842.html