Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;

import java.io.File;

import java.io.FileWriter;
import java.io.IOException;

public class Main {
    /**
     * write a string To a File
     * 
     * @param context
     * @param file
     * @param string
     * @param isAppend
     * @return
     */
    public static boolean writeStringToFile(File file, String string, boolean isAppend) {
        boolean isWriteOk = false;

        if (null == file || null == string) {
            return isWriteOk;
        }

        FileWriter fw = null;
        try {
            fw = new FileWriter(file, isAppend);

            fw.write(string, 0, string.length());
            fw.flush();
            isWriteOk = true;
        } catch (Exception e) {
            isWriteOk = false;
            e.printStackTrace();
        } finally {
            if (fw != null) {
                try {
                    fw.close();
                } catch (IOException e) {
                    isWriteOk = false;
                    e.printStackTrace();
                }
            }
        }
        return isWriteOk;
    }
}