Java Text File Write writeStringToFile(String fullPath, String content)

Here you can find the source of writeStringToFile(String fullPath, String content)

Description

write String To File

License

Apache License

Declaration

public static boolean writeStringToFile(String fullPath, String content) 

Method Source Code

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

import java.io.BufferedWriter;

import java.io.File;

import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.Writer;

public class Main {
    public static boolean writeStringToFile(String fullPath, String content) {
        try {//from w ww  .  j  a  v  a  2  s . com
            Writer output = null;
            File file = new File(fullPath);
            if (!file.exists()) {
                file.createNewFile();
            }
            output = new BufferedWriter(new FileWriter(file));
            output.write(content);
            output.close();
        } catch (IOException ex) {
            ex.printStackTrace();
            return false;
        }
        return true;
    }

    /**
     * Closes InputStream and/or OutputStream. It makes sure that both streams
     * tried to be closed, even first throws an exception.
     *
     * @throw IOException if stream (is not null and) cannot be closed.
     *
     */
    protected static void close(InputStream iStream, OutputStream oStream) throws IOException {
        try {
            if (iStream != null) {
                iStream.close();
            }
        } finally {
            if (oStream != null) {
                oStream.close();
            }
        }
    }
}

Related

  1. writeStringToFile(String filename, String string, boolean overwrite)
  2. writeStringToFile(String filename, String stringToWrite)
  3. writeStringToFile(String filename, String text)
  4. WriteStringToFile(String fn, String dest)
  5. writeStringToFile(String fullPath, byte[] fileBytes)
  6. writeStringToFile(String jsonStr, File file)
  7. writeStringToFile(String macroContent, File file)
  8. writeStringToFile(String modifiedLine, String filePath)
  9. writeStringToFile(String path, String content)