Java Text File Save writeFile(File outputDirectory, String fileName, String source)

Here you can find the source of writeFile(File outputDirectory, String fileName, String source)

Description

write File

License

Open Source License

Declaration

public static void writeFile(File outputDirectory, String fileName, String source) throws Exception 

Method Source Code


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

import java.io.*;

public class Main {
    public static void writeFile(File outputDirectory, String fileName, String source) throws Exception {
        File path = new File(outputDirectory.getAbsolutePath());
        if (!path.exists()) {
            path.mkdirs();/*  w  ww  .j  a  v  a 2s.  c  o  m*/
        }

        File file = new File(path, fileName);

        if (!file.exists()) {
            file.createNewFile();
        }

        System.out.println("Generating: " + file.getAbsolutePath());
        try (FileOutputStream fos = new FileOutputStream(file)) {
            fos.write(source.trim().getBytes());
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        }
    }
}

Related

  1. serialize(final File folder, final String content, final String fileName)
  2. setText(File file, String text)
  3. writeFile(ArrayList lines, String dest_path)
  4. writeFile(Collection emailTree, String destFile)
  5. writeFile(File destinationFile, String contents, String encoding)
  6. writeFile(File outputFile, ArrayList sortedLines, String lineSeparator)
  7. writeFile(File outputFile, String text)
  8. writeFile(File outputFolder, String fileName, String content)
  9. writeFile(File path, File file, String content)