Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
import android.os.Environment;

import android.util.Log;

import java.io.DataInputStream;

import java.io.EOFException;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;

import java.io.IOException;

public class Main {
    final private static String TAG = "IOHelper";

    public static float[] readBinFloat(String dir, String fileName, int size) {
        float x;
        int i = 0;
        float[] tab = new float[size];
        File sdLien = Environment.getExternalStorageDirectory();
        File inFile = new File(sdLien + File.separator + dir + File.separator + fileName);
        Log.d(TAG, "path of file : " + inFile);
        if (!inFile.exists()) {
            throw new RuntimeException("File doesn't exist");
        }
        DataInputStream in = null;
        try {
            in = new DataInputStream(new FileInputStream(inFile));
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        }
        try {
            x = in.readFloat();
            while (i < size) {
                tab[i] = x;
                i++;
                x = in.readFloat();
            }
        } catch (EOFException e) {
            try {
                Log.d(TAG, "close");
                in.close();
            } catch (IOException e1) {
                e1.printStackTrace();
            }
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            if (in != null) {
                try { //free ressources
                    Log.d(TAG, "close");
                    in.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
        return tab;
    }
}