⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 fixedlengthstringio.java

📁 java程序设计导论(daniel liang著) 所有偶数课后习题答案
💻 JAVA
字号:
import java.io.*;public class FixedLengthStringIO {  // Read fixed number of characters from a DataInput stream  public static String readFixedLengthString(int size,    DataInput in) throws IOException {    // Declare an array of characters    char[] chars = new char[size];    // Read fixed number of characters to the array    for (int i = 0; i < size; i++)      chars[i] = in.readChar();    return new String(chars);  }  // Write fixed number of characters to a DataOutput stream  public static void writeFixedLengthString(String s, int size,    DataOutput out) throws IOException {    char[] chars = new char[size];        // Write characters from string into an array    s.getChars(0, s.length(), chars, 0);        // Fill in blank characters in the rest of the array    for (int i = Math.min(s.length(), size); i < chars.length; i++)      chars[i] = ' ';         // Create and write a new string padded with blank characters    out.writeChars(new String(chars));  }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -