Java Text File Write writeStringToFile(String str, File file)

Here you can find the source of writeStringToFile(String str, File file)

Description

write String To File

License

Apache License

Declaration

public static File writeStringToFile(String str, File file) 

Method Source Code


//package com.java2s;
//License from project: Apache License 

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;

import java.io.FileWriter;

import java.io.PrintWriter;
import java.io.StringReader;

public class Main {

    public static File writeStringToFile(String str, File file) {
        try {/* w ww. j  a  v a2 s  .  c o m*/
            BufferedReader in4 = new BufferedReader(new StringReader(str));
            PrintWriter out1 = new PrintWriter(new BufferedWriter(new FileWriter(file)));
            String tempStr = null;
            while ((tempStr = in4.readLine()) != null) {
                out1.println(tempStr);
            }
            out1.close();
        } catch (Exception e) {
            e.printStackTrace();
        }
        return file;
    }
}

Related

  1. writeStringToFile(String s, String filename)
  2. writeStringToFile(String s, String filePathname)
  3. writeStringToFile(String sdat, File f)
  4. writeStringToFile(String str, File file)
  5. writeStringToFile(String str, File file)
  6. WriteStringToFile(String str, String file)
  7. writeStringToFile(String str, String filePath)
  8. writeStringToFile(String str, String filePath)
  9. writeStringToFile(String string, File destFile)