Example usage for java.io RandomAccessFile close

List of usage examples for java.io RandomAccessFile close

Introduction

In this page you can find the example usage for java.io RandomAccessFile close.

Prototype

public void close() throws IOException 

Source Link

Document

Closes this random access file stream and releases any system resources associated with the stream.

Usage

From source file:MeCabBench.java

public static void main(String[] args) {
    try {/*from  w  ww .  j a v a 2  s  .c  om*/
        if (args.length == 0) {
            System.out.println("usage: java MeCabBench file [file ..]");
            System.exit(2);
        }

        Tagger tagger = new Tagger(new String[] { "java", "-d", dicPath });

        long processed = 0;
        long nbytes = 0;
        long nchars = 0;

        long start = System.currentTimeMillis();
        for (int a = 0; a < args.length; a++) {
            String text = "";
            try {
                RandomAccessFile raf = new RandomAccessFile(args[a], "r");
                byte[] buf = new byte[(int) raf.length()];
                raf.readFully(buf);
                raf.close();
                text = new String(buf, encoding);
                nbytes += buf.length;
                nchars += text.length();
            } catch (IOException ioe) {
                log.error(ioe);
                continue;
            }

            long s_start = System.currentTimeMillis();
            for (int c = 0; c < repeat; c++)
                doWork(tagger, text);
            long s_end = System.currentTimeMillis();
            processed += (s_end - s_start);
        }
        long end = System.currentTimeMillis();
        System.out.println("number of files: " + args.length);
        System.out.println("number of repeat: " + repeat);
        System.out.println("number of bytes: " + nbytes);
        System.out.println("number of chars: " + nchars);
        System.out.println("total time elapsed: " + (end - start) + " msec.");
        System.out.println("analysis time: " + (processed) + " msec.");
    } catch (Exception e) {
        e.printStackTrace(System.err);
        System.exit(1);
    }
}

From source file:Main.java

public static void main(String[] args) {
    try {/*  w  w  w . j av a 2s  . c om*/
        boolean b = true;
        RandomAccessFile raf = new RandomAccessFile("c:/test.txt", "rw");

        raf.writeBoolean(false);

        raf.seek(0);

        System.out.println(raf.readBoolean());

        raf.writeBoolean(b);

        raf.seek(1);

        System.out.println(raf.readBoolean());
        raf.close();
    } catch (IOException ex) {
        ex.printStackTrace();
    }

}

From source file:Main.java

public static void main(String[] args) {
    try {//from   ww w.ja va2  s  . c  o  m
        int f = 1234;

        RandomAccessFile raf = new RandomAccessFile("c:/test.txt", "rw");

        raf.writeInt(f);

        raf.seek(0);

        System.out.println(raf.readInt());

        raf.seek(0);

        raf.writeInt(200);

        raf.seek(0);

        System.out.println(raf.readInt());
        raf.close();
    } catch (IOException ex) {
        ex.printStackTrace();
    }

}

From source file:Main.java

public static void main(String[] args) {
    try {/*from w  w  w  .  jav  a2 s  . c  o  m*/
        int i = 70;

        RandomAccessFile raf = new RandomAccessFile("c:/test.txt", "rw");

        raf.writeChar(i);

        raf.seek(0);

        System.out.println(raf.readChar());

        raf.seek(0);

        raf.writeChar(71);

        raf.seek(0);

        System.out.println(raf.readChar());
        raf.close();
    } catch (IOException ex) {
        ex.printStackTrace();
    }

}

From source file:Main.java

public static void main(String[] args) {
    try {//  ww  w .  ja  va 2  s .  c  o  m
        short s = 15;

        RandomAccessFile raf = new RandomAccessFile("c:/test.txt", "rw");

        raf.writeShort(s);

        raf.seek(0);

        System.out.println(raf.readShort());

        raf.seek(0);

        raf.writeShort(20);

        raf.seek(0);

        System.out.println(raf.readShort());
        raf.close();
    } catch (IOException ex) {
        ex.printStackTrace();
    }

}

From source file:Main.java

public static void main(String[] args) {
    try {//from  w w w .  j  ava 2  s.c o  m
        byte[] b1 = { 15, 8 };

        RandomAccessFile raf = new RandomAccessFile("c:/test.txt", "rw");

        raf.writeByte(b1[0]);

        raf.seek(0);

        System.out.println(raf.readByte());

        raf.seek(0);

        raf.writeByte(b1[1]);

        raf.seek(0);

        System.out.println(raf.readByte());
        raf.close();
    } catch (IOException ex) {
        ex.printStackTrace();
    }

}

From source file:Main.java

public static void main(String[] args) {
    try {//from www  .  jav  a 2s  .com
        long f = 123456789909876L;

        RandomAccessFile raf = new RandomAccessFile("c:/test.txt", "rw");

        raf.writeLong(f);

        raf.seek(0);

        System.out.println(raf.readLong());

        raf.seek(0);

        raf.writeLong(20000000000l);

        raf.seek(0);

        System.out.println(raf.readLong());
        raf.close();
    } catch (IOException ex) {
        ex.printStackTrace();
    }

}

From source file:Main.java

public static void main(String[] args) {
    try {/*from  w  w  w . j  a v a2 s  . co  m*/
        float f = 1234.5678f;

        RandomAccessFile raf = new RandomAccessFile("c:/test.txt", "rw");

        raf.writeFloat(f);

        raf.seek(0);

        System.out.println(raf.readFloat());

        raf.seek(0);

        raf.writeFloat(123.4567f);

        raf.seek(0);

        System.out.println(raf.readFloat());
        raf.close();
    } catch (IOException ex) {
        ex.printStackTrace();
    }

}

From source file:Main.java

public static void main(String[] args) {
    try {/*from  ww  w . ja  v  a2  s  .  co  m*/
        double d = 1234.5678;

        RandomAccessFile raf = new RandomAccessFile("c:/test.txt", "rw");

        raf.writeDouble(d);

        raf.seek(0);

        System.out.println(raf.readDouble());

        raf.seek(0);

        raf.writeDouble(123.4567);

        raf.seek(0);

        System.out.println(raf.readDouble());
        raf.close();
    } catch (IOException ex) {
        ex.printStackTrace();
    }

}

From source file:Main.java

public static void main(String[] args) {
    try {//from   www.java  2 s.  com
        int b1 = 15;
        int b2 = 20;

        RandomAccessFile raf = new RandomAccessFile("c:/test.txt", "rw");
        raf.write(b1);

        // set the file pointer at 0 position
        raf.seek(0);

        System.out.println(raf.readByte());

        raf.write(b2);

        raf.seek(1);

        System.out.println(raf.readByte());
        raf.close();
    } catch (IOException ex) {
        ex.printStackTrace();
    }

}