Java Text File Save writeFile(String txt, File fyl)

Here you can find the source of writeFile(String txt, File fyl)

Description

Write a file.

License

Open Source License

Parameter

Parameter Description
txt the text to output to file.
fyl the file to write to.

Exception

Parameter Description
FileNotFoundException , IOException if something goes wrong.

Declaration

public synchronized static void writeFile(String txt, File fyl) throws FileNotFoundException, IOException 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

import java.io.BufferedOutputStream;
import java.io.File;

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

public class Main {
    /**/*from   w w w  .ja v  a 2  s.  c o m*/
     * Write a file.
     * @param txt the text to output to file.
     * @param fyl the file to write to.
     * @throws FileNotFoundException, IOException if something goes wrong.
     */
    public synchronized static void writeFile(String txt, File fyl) throws FileNotFoundException, IOException {

        writeFile(txt.getBytes(), fyl);

    }

    /**
     * Write a file.
     * @param bites the array of bytes to output to file.
     * @param fyl the file to write to.
     * @throws FileNotFoundException, IOException if something goes wrong.
     */
    public synchronized static void writeFile(byte[] bites, File fyl) throws FileNotFoundException, IOException {

        BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream(fyl));
        bos.write(bites);
        bos.flush();
        bos.close();

    }
}

Related

  1. writeFile(String tailored, File f)
  2. writeFile(String targetPath, String filename, byte[] content)
  3. writeFile(String text, File file, boolean append)
  4. writeFile(String text, File outf)
  5. writeFile(String text, File target)