Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
//License from project: Apache License 

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.File;
import java.io.InputStream;
import java.io.FileInputStream;
import java.io.IOException;

public class Main {
    public static String slurp(File file) throws IOException {
        String body = "";
        InputStream is = null;
        try {
            is = new FileInputStream(file);
            body = slurp(is);
        } finally {
            if (is != null) {
                is.close();
            }
        }
        return body;
    }

    public static String slurp(InputStream is) throws IOException {
        String line;
        BufferedReader reader = null;
        StringBuffer buf = new StringBuffer("");
        try {
            reader = new BufferedReader(new InputStreamReader(is));

            while ((line = reader.readLine()) != null) {
                if (line.indexOf("#") == 0) {
                    buf.append("\n");
                    continue;
                }
                buf.append(line).append("\n");
            }
        } finally {
            if (null != is) {
                is.close();
            }
            if (null != reader) {
                reader.close();
            }
        }
        return buf.toString();
    }
}