Here you can find the source of writeStringToFile(String contents, File outfile)
Parameter | Description |
---|---|
contents | The string containing the contents of the file |
outfile | The File object identifying the location of the file |
public static void writeStringToFile(String contents, File outfile)
//package com.java2s; // Licensed under the Apache License, Version 2.0 (the "License"); import java.io.*; public class Main { /**/*from w w w.j ava2 s . c om*/ * Write a string to a specified file. * * @param contents The string containing the contents of the file * @param outfile The File object identifying the location of the file */ public static void writeStringToFile(String contents, File outfile) { try { BufferedWriter bw = new BufferedWriter(new FileWriter(outfile)); bw.write(contents); bw.flush(); bw.close(); } catch (IOException ioe) { System.out.println("Input error writing to " + outfile.getName()); } return; } }