Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
import java.io.FileInputStream;
import java.io.IOException;

public class Main {
    /**
     * Use the file and count the chars in the file, so we can use static arrays
     * 
     * @param fileName
     * @return integer with the size of the file
     */
    public static int countBytes(String fileName) {
        FileInputStream fin;
        int charCount = 0;
        try {
            // Open an input stream
            fin = new FileInputStream(fileName);
            while (fin.available() != 0) {
                fin.read();
                charCount++;
            }
            fin.close();
        }
        // Catches any error conditions
        catch (IOException e) {
            System.err.println("Unable to read image");
            System.exit(1);
        }
        return charCount;
    }
}