Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;

import java.io.DataInputStream;
import java.io.File;
import java.io.FileInputStream;

import java.io.IOException;
import java.io.InputStream;

public class Main {
    public static String readFile(String path) throws IOException {
        InputStream is = new FileInputStream(new File(path));
        DataInputStream ds = new DataInputStream(is);
        // Estimated capacity, potential risk ???
        byte[] bytes = new byte[is.available()];
        ds.readFully(bytes);
        String text = new String(bytes);
        is.close();
        ds.close();
        return text;
    }
}