将固定的字符串写入DataOutput
//package com.nowjava; import java.io.*;/* 来自 N o w J a v a . c o m*/ 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 out.writeChar(0); //write Unicode zero } } }