首页 > 其他 > 详细

write file

时间:2019-06-16 16:39:05      阅读:107      评论:0      收藏:0      [点我收藏+]
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+"\r\n");
                out.write(sb.toString().getBytes("utf-8"));//注意需要转换对应的字符集

            }

            out.close();
        }
        catch(IOException ex)
        {
            System.out.println(ex.getStackTrace());
        }
    }

write file

原文:https://www.cnblogs.com/feelgood/p/11031842.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!