MainClass.java Source code

Java tutorial

Introduction

Here is the source code for MainClass.java

Source

import java.util.logging.FileHandler;
import java.util.logging.Logger;
import java.util.logging.SimpleFormatter;

public class MainClass {
    private static Logger logger = Logger.getLogger("LogToFile2");

    public static void main(String[] args) throws Exception {
        FileHandler logFile = new FileHandler("LogToFile2.txt");
        logFile.setFormatter(new SimpleFormatter());
        logger.addHandler(logFile);
        logger.info("A message logged to the file");
    }
}