Java Text File Save writefile(String path, String content, boolean append)

Here you can find the source of writefile(String path, String content, boolean append)

Description

writefile

License

Open Source License

Declaration

public static void writefile(String path, String content, boolean append) 

Method Source Code

//package com.java2s;
/**/*from   w w w. ja va 2s . com*/
 * Copyright &copy; 2012-2013 <a href="https://github.com/thinkgem/jeesite">JeeSite</a> All rights reserved.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 */

import java.io.BufferedWriter;
import java.io.File;

import java.io.FileWriter;

public class Main {
    public static void writefile(String path, String content, boolean append) {
        BufferedWriter bw;
        File targetFile;
        try {
            targetFile = new File(path);
            if (targetFile.exists() == false) {
                targetFile.createNewFile();
            }
            FileWriter fw = new FileWriter(targetFile, append);
            bw = new BufferedWriter(fw);
            bw.write(content + "\n");
            bw.flush();
            bw.close();
        } catch (Exception d) {
            System.out.println(d.getMessage());
        }
    }
}

Related

  1. writeFile(String filePath, List lines)
  2. writefile(String path, String content)
  3. writefile(String path, String content)
  4. writeFile(String path, String content)
  5. writeFile(String path, String content)
  6. writeFile(String path, String contents)
  7. writeFile(String path, String data)
  8. writeFile(String path, String fileName, String content)
  9. writeFile(String path, String fileName, String content, String charset)