Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;

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

import java.io.FileWriter;

public class Main {
    /**
     * Write to file in given folder
     * @param fcontent
     * @return
     */
    public static boolean writeFile(String fcontent, String path) {

        /*
         * Write file contents to file path
         */
        try {
            File file = new File(path);
            // If file does not exists, then create it
            if (!file.exists()) {
                file.createNewFile();
            }
            FileWriter fw = new FileWriter(file.getAbsoluteFile());
            BufferedWriter bw = new BufferedWriter(fw);
            bw.write(fcontent);
            bw.close();
            return true;
        } catch (Exception e) {
            return false;
        }
    }
}