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.FileOutputStream;
import java.io.IOException;

import java.io.OutputStreamWriter;
import java.io.PrintWriter;

public class Main {
    /**
     * This method get string and create local file with that string
     * @param st
     * @param fileName
     */
    private static void writeFile(String st, String fileName) {
        FileOutputStream fos = null;
        PrintWriter pw = null;

        try {
            File rootDir = new File("/storage/emulated/0/dbSuperZol/");

            fos = new FileOutputStream(new File(rootDir, fileName));
            pw = new PrintWriter(new BufferedWriter(new OutputStreamWriter(fos)));

            pw.println(st);

        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            if (pw != null) {
                pw.close();
            }
            if (fos != null) {
                try {
                    fos.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }

        }
    }
}