Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

import java.io.File;
import java.io.FileOutputStream;
import java.io.PrintStream;

public class Main {
    public static void main(String[] argv) {
        saveFile("c:\\a.txt", "value");
    }

    public static void saveFile(final String fileName, final String str) {
        try {
            File f = new File(fileName);
            if (new File(f.getParent()).exists() == false) {
                f.getParentFile().mkdirs();
            }
            f.createNewFile();
            PrintStream p = new PrintStream(new FileOutputStream(f, false));
            p.println(str);
            p.close();

        } catch (Exception e) {
            e.printStackTrace();
            System.err.println(fileName);
        }
    }
}