read Long from RandomAccessFile - Android java.io

Android examples for java.io:RandomAccessFile

Description

read Long from RandomAccessFile

Demo Code


//package com.java2s;
import java.io.File;
import java.io.IOException;
import java.io.RandomAccessFile;

public class Main {
    private static long readLong(String file) {
        RandomAccessFile raf = null;

        try {//  w w  w . j  a  v  a2 s  .  c om
            raf = getFile(file);
            return Long.valueOf(raf.readLine());
        } catch (Exception e) {
            return 0;
        } finally {
            if (raf != null) {
                try {
                    raf.close();
                } catch (IOException e) {
                }
            }
        }
    }

    private static RandomAccessFile getFile(String filename)
            throws IOException {
        File f = new File(filename);
        return new RandomAccessFile(f, "r");
    }
}

Related Tutorials