read Fixed String from DataInput - Java File Path IO

Java examples for File Path IO:Text File

Description

read Fixed String from DataInput

Demo Code

//package com.java2s;
import java.io.*;

public class Main {
    public static String readFixedString(DataInput in, int length)
            throws IOException {
        StringBuilder sb = new StringBuilder();
        for (int i = 0; i < length; i++) {
            char c = in.readChar();
            //if char is not Unicode zero add
            if (c != 0)
                sb.append(c);//  ww w  .  j a  v  a  2 s .  com
        }
        return sb.toString();
    }
}

Related Tutorials