天天看點

java代碼将list按行寫入到txt檔案中

/**
	 * 将list按行寫入到txt檔案中
	 * @param strings
	 * @param path
	 * @throws Exception
	 */
	public static void writeFileContext(List<String>  strings, String path) throws Exception {
		File file = new File(path);
        //如果沒有檔案就建立
        if (!file.isFile()) {
            file.createNewFile();
        }
        BufferedWriter writer = new BufferedWriter(new FileWriter(path));
        for (String l:strings){
            writer.write(l + "\r\n");
        }
        writer.close();
    }