Here you can find the source of saveFileContents(File file, String contents)
public static void saveFileContents(File file, String contents)
//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); } } }