Java tutorial
//package com.java2s; //License from project: Creative Commons License import java.io.IOException; import java.io.RandomAccessFile; import java.nio.charset.Charset; public class Main { private final static Charset LATIN1 = Charset.availableCharsets().get("ISO-8859-1"); /** * Read a Pascal string from the file. */ public static String readPascalString(RandomAccessFile raf) throws IOException { int len = raf.read(); byte[] buf = new byte[len + 1]; raf.read(buf, 1, len); buf[0] = (byte) len; return bytesToPascalString(buf); } /** * Convert a byte array to a Pascal string. The first byte is the byte count, * followed by that many active characters. */ public static String bytesToPascalString(byte[] data) { int len = (int) data[0]; return new String(data, 0, len, LATIN1); } }