Java Write String to File writeFile(String filePath, String content)

Here you can find the source of writeFile(String filePath, String content)

Description

ananya.tools.utils.FileUtils method to write string content to a file

License

Apache License

Parameter

Parameter Description
filePath a parameter
content a parameter

Declaration

public static void writeFile(String filePath, String content) 

Method Source Code


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

import java.io.*;

public class Main {
    /**// ww w  .  j  a v a2  s.c o m
     *  ananya.tools.utils.FileUtils method to write string content to a file
     * @param filePath
     * @param content
     */
    public static void writeFile(String filePath, String content) {

        writeFile(new File(filePath), content);
    }

    public static void writeFile(File file, String content) {
        try {
            FileWriter writer = new FileWriter(file);
            writer.write(content);
            writer.flush();
            writer.close();
            System.out.println("Content Written to " + file.getAbsolutePath());

        } catch (IOException e) {
            System.err.println("Exception When writing the corpus file " + e.getMessage());
        }
    }
}

Related

  1. writeFile(String fileName, String text, String characterEncoding)
  2. writeFile(String fileName, String textToSave)
  3. writeFile(String fileName, String[] contents)
  4. writeFile(String fileName, String[] lines)
  5. writeFile(String filename, StringBuilder sb)
  6. writeFile(String filePath, String content)
  7. WriteFile(String filepath, String content)
  8. writeFile(String filePath, String content)
  9. writeFile(String filePath, String content)