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.DataInputStream;

import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {
    public static String textFromFile(String filename) {

        String text = new String();
        String nextLine = new String();

        try {
            FileInputStream instream = new FileInputStream(filename);
            DataInputStream in = new DataInputStream(instream);

            BufferedReader buffered = new BufferedReader(new InputStreamReader(in));

            while ((nextLine = buffered.readLine()) != null) {
                text = text.concat(nextLine);
            }
        } catch (IOException e) {
            return null;
        }

        return text;
    }
}