Java Text File Write writeStringToFile(String contents, File outfile)

Here you can find the source of writeStringToFile(String contents, File outfile)

Description

Write a string to a specified file.

License

Apache License

Parameter

Parameter Description
contents The string containing the contents of the file
outfile The File object identifying the location of the file

Declaration

public static void writeStringToFile(String contents, File outfile) 

Method Source Code


//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;
    }
}

Related

  1. writeStringToFile(String content, String filename)
  2. writeStringToFile(String content, String fileName, boolean append)
  3. writeStringToFile(String content, String filePath)
  4. writeStringToFile(String content, String path)
  5. writeStringtoFile(String content, String path)
  6. writeStringToFile(String contents, File outputFile)
  7. writeStringToFile(String contents, String path)
  8. writeStringToFile(String contents, String path, String encoding)
  9. writeStringToFile(String data, String filename, boolean append)