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()); } }