write Fixed String to DataOutput - Java File Path IO

Java examples for File Path IO:Text File

Description

write Fixed String to DataOutput

Demo Code

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

public class Main {
    public static void writeFixedString(DataOutput out, int length, String s)
            throws IOException {
        for (int i = 0; i < length; i++) {
            if (i < s.length())
                out.writeChar(s.charAt(i)); //write char
            else/* www  .  j av a2s  .  c  om*/
                out.writeChar(0); //write Unicode zero
        }
    }
}

Related Tutorials