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

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

Description

write File

License

Open Source License

Declaration

public static void writeFile(File target, String content) 

Method Source Code


//package com.java2s;
//License from project: Open Source License 

import java.io.*;

public class Main {
    public static void writeFile(File target, String content) {
        PrintWriter p = null;/*from  w  w  w.  j  a  v a 2 s  .  co m*/
        try {
            p = new PrintWriter(new FileWriter(target));
            p.write(content);
        } catch (Exception e) {
            throw new RuntimeException("Problems writing text to file: " + target);
        } finally {
            close(p);
        }
    }

    /**
     * Closes the target. Does nothing when target is null. Is not silent, throws exception on IOException.
     *
     * @param closeable the target, may be null
     */
    public static void close(Closeable closeable) {
        if (closeable != null) {
            try {
                closeable.close();
            } catch (IOException e) {
                throw new RuntimeException("Problems closing stream", e);
            }
        }
    }
}

Related

  1. writeFile(File outputFile, ArrayList sortedLines, String lineSeparator)
  2. writeFile(File outputFile, String text)
  3. writeFile(File outputFolder, String fileName, String content)
  4. writeFile(File path, File file, String content)
  5. writeFile(File path, String fileName, String fileContent)
  6. writeFile(final byte[] content, final String path)
  7. writeFile(final File destination, final List contents)
  8. writeFile(final File f, final String content)
  9. writeFile(final File outputFile, final String data, final String encoding)