?? pushbackstreamdemo.java
字號:
package onlyfun.caterpillar;
import java.io.*;
public class PushbackStreamDemo {
public static void main(String[] args) {
try {
PushbackInputStream pushbackInputStream =
new PushbackInputStream(
new FileInputStream(args[0]));
byte[] array = new byte[2];
int tmp = 0;
int count = 0;
while((count = pushbackInputStream.read(array))
!= -1) {
// 兩個字節轉換為整數
tmp = (short)((array[0] << 8) |
(array[1] & 0xff));
tmp = tmp & 0xFFFF;
// 判斷是否為BIG5,如果是則顯示BIG5中文字
if(tmp >= 0xA440 && tmp < 0xFFFF) {
System.out.println("BIG5: " +
new String(array));
}
else {
// 將第二個字節推回流
pushbackInputStream.unread(array, 1, 1);
// 顯示ASCII范圍的字符
System.out.println("ASCII: " +
(char)array[0]);
}
}
pushbackInputStream.close();
}
catch(ArrayIndexOutOfBoundsException e) {
System.out.println("請指定文件名稱");
}
catch(IOException e) {
e.printStackTrace();
}
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -