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

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

Description

write String To File

License

Apache License

Declaration

public static File writeStringToFile(String string, File file)
            throws UnsupportedEncodingException, FileNotFoundException, IOException 

Method Source Code


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

import java.io.File;

import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;

import java.io.OutputStreamWriter;

import java.io.UnsupportedEncodingException;

public class Main {
    public static File writeStringToFile(String string, File file)
            throws UnsupportedEncodingException, FileNotFoundException, IOException {
        try (OutputStreamWriter writer = new OutputStreamWriter(new FileOutputStream(file), "UTF-8")) {
            writer.write(string);/*from  w  ww. j av a  2s . co  m*/
        }

        return file;
    }
}

Related

  1. writeStringToFile(String str, String filePath)
  2. writeStringToFile(String string, File destFile)
  3. writeStringToFile(String string, File dstFile)
  4. writeStringToFile(String string, File file)
  5. writeStringToFile(String string, File file)
  6. writeStringToFile(String string, File file)
  7. writeStringToFile(String string, String fileName)
  8. writeStringToFile(String string, String fileName, boolean append)
  9. writeStringToFile(String string, String path)