Java FileWriter Write saveFileContents(File file, String contents)

Here you can find the source of saveFileContents(File file, String contents)

Description

save File Contents

License

Apache License

Declaration

public static void saveFileContents(File file, String contents) 

Method Source Code

//package com.java2s;
//   Licensed under the Apache License, Version 2.0 (the "License");

import java.io.File;

import java.io.FileWriter;
import java.io.IOException;

public class Main {
    public static void saveFileContents(File file, String contents) {
        try {//  w ww . j a  va 2 s . c  o m
            FileWriter fw = new FileWriter(file);
            fw.write(contents);
            fw.close();
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }

    /**
     * Saves the file contents to a file.
     * 
     * @param filename
     *            the filename.
     * @param contents
     *            the file contents.
     */
    public static void saveFileContents(String filename, String contents) {
        try {
            File file = new File(filename);
            if (!file.exists()) {
                file.createNewFile();
            }
            saveFileContents(file, contents);
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }
}

Related

  1. saveFile(String path, Map> setup)
  2. saveFile(String path, String content)
  3. SaveFile(String path, String data, boolean deleteOnExit)
  4. saveFile(String path, String sb)
  5. saveFile(String[] lines, String savedName, String extension)
  6. saveFileFromString(File file, String encoding, String content)
  7. saveFiles(final List contents, final File outputDirectory, final String outputName, final String fileExtension)
  8. saveFlows(Map differences, String file)
  9. saveFormedClustersToFile(Vector names, Collection> clusters, String filename)