Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;

public class Main {
    public static String readString(String fileName) {
        File file = new File(fileName);
        return readString(file);
    }

    public static String readString(File file) {
        StringBuilder builder = new StringBuilder();
        if (!file.exists()) {
            System.err.println("Can't Find " + file);
        }

        try {
            BufferedReader in = new BufferedReader(new FileReader(file));
            String str;
            while ((str = in.readLine()) != null) {
                //System.out.println(str);
                builder.append(str);
            }
            in.close();
        } catch (IOException e) {
            e.getStackTrace();
        }
        return builder.toString();
    }
}