Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;

import java.io.*;

public class Main {

    public static boolean string2File(String res, File file) {
        if (file == null || res == null)
            return false;
        BufferedWriter bufferedWriter = null;
        try {
            bufferedWriter = new BufferedWriter(new FileWriter(file));
            bufferedWriter.write(res);
            bufferedWriter.flush();
            return true;
        } catch (IOException e) {
            e.printStackTrace();
            if (file.exists())
                file.delete();
            return false;
        } finally {
            try {
                if (bufferedWriter != null)
                    bufferedWriter.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }
}