Reads 4 bytes and concatenates them into a String from RandomAccessFile - Java File Path IO

Java examples for File Path IO:RandomAccessFile

Description

Reads 4 bytes and concatenates them into a String from RandomAccessFile

Demo Code


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

public class Main {
    /**/*from  w w  w .  j  a  va2 s  .c om*/
     *   Reads 4 bytes and concatenates them into a String.
     *   This pattern is used for ID's of various kinds.
     */
    public static String read4Chars(RandomAccessFile raf)
            throws IOException {
        StringBuffer sbuf = new StringBuffer(4);
        for (int i = 0; i < 4; i++) {
            char ch = (char) raf.read();
            sbuf.append(ch);
        }
        return sbuf.toString();
    }
}

Related Tutorials