Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
//| Licensed under the Apache License, Version 2.0 (the "License");         |

import java.io.IOException;

import java.io.InputStreamReader;

public class Main {
    /** read a resource as a String
     * 
     * @param clazz
     * @param name
     * @return
     * @throws IOException
     */
    public static String readResourceAsString(Class clazz, String name) throws IOException {
        StringBuffer fileData = new StringBuffer(1000);
        InputStreamReader reader = new InputStreamReader(clazz.getResourceAsStream(name));
        char[] buf = new char[1024];
        int numRead = 0;
        while ((numRead = reader.read(buf)) != -1) {
            String readData = String.valueOf(buf, 0, numRead);
            fileData.append(readData);
            buf = new char[1024];
        }
        reader.close();
        return fileData.toString().replace("\r\n", "\n");
    }
}