Java Text File Save writeFile(String path, String content)

Here you can find the source of writeFile(String path, String content)

Description

write File

License

Apache License

Declaration

public static String writeFile(String path, String content) throws IOException 

Method Source Code

//package com.java2s;
//License from project: Apache License 

import java.io.BufferedOutputStream;

import java.io.File;

import java.io.FileOutputStream;

import java.io.IOException;

import java.io.OutputStream;

public class Main {

    public static String writeFile(String path, String content) throws IOException {
        byte[] matter = content.getBytes("GBK");
        return writeFile(path, matter, false);
    }//  w w w.j a  v  a2s.c om

    public static String writeFile(String path, String content, boolean append) throws IOException {
        byte[] matter = content.getBytes("GBK");
        return writeFile(path, matter, append);
    }

    public static String writeFile(String path, byte[] content) throws IOException {
        return writeFile(path, content, false);
    }

    public static String writeFile(String path, byte[] content, boolean append) throws IOException {
        if (path == null || path.length() == 0) {
            path = File.createTempFile("writeServerFile", ".file").getAbsolutePath();
        } else {
            path = new File(path).getAbsolutePath();
        }
        OutputStream os = null;
        try {
            os = new BufferedOutputStream(new FileOutputStream(path, append));
            os.write(content);
            os.flush();
        } finally {
            if (os != null) {
                os.close();
            }
        }
        return path;
    }
}

Related

  1. writeFile(String file, String content)
  2. writeFile(String file, String text)
  3. writeFile(String filePath, List lines)
  4. writeFile(String path, String content)
  5. writefile(String path, String content)
  6. writefile(String path, String content)
  7. writefile(String path, String content, boolean append)
  8. writeFile(String path, String contents)
  9. writeFile(String path, String data)