MainClass.java Source code

Java tutorial

Introduction

Here is the source code for MainClass.java

Source

import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.util.Scanner;

public class MainClass {
    public static void main(String args[]) throws IOException {
        // Write output to a file.
        FileWriter fout = new FileWriter("test.txt");
        fout.write("int: 1  double 1.0  boolean true");
        fout.close();

        FileReader fin = new FileReader("Test.txt");

        Scanner src = new Scanner(fin);

        while (src.hasNext()) {
            if (src.hasNextInt()) {
                System.out.println("int: " + src.nextInt());
            } else if (src.hasNextDouble()) {
                System.out.println("double: " + src.nextDouble());
            } else if (src.hasNextBoolean()) {
                System.out.println("boolean: " + src.nextBoolean());
            } else {
                System.out.println(src.next());
            }
        }
        fin.close();
    }
}