Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;

import java.io.FileInputStream;

public class Main {
    /**
     * Read data from file.
     *
     * @param fileName
     * @return
     */
    public static String readFile(String fileName) {
        String ret = "";
        try {
            FileInputStream fin = new FileInputStream(fileName);
            int length = fin.available();
            byte[] buffer = new byte[length];
            fin.read(buffer);
            //         ret = EncodingUtils.getString(buffer, "UTF-8");
            ret = buffer.toString();
            fin.close();
        } catch (Exception e) {
            e.printStackTrace();
        }
        return ret;
    }
}