黑马程序员技术交流社区
标题:
用字节流在控制台完美输出中文的方法
[打印本页]
作者:
我有上将潘凤
时间:
2016-6-7 15:21
标题:
用字节流在控制台完美输出中文的方法
public class ShowChinese {
public static void main(String[] args) throws IOException {
FileInputStream fis = new FileInputStream("点招面试题总结.java");
byte[] by = new byte[1024];
int len;
int count = 0;
byte mid = 0;
String str;
while ((len = fis.read(by)) != -1) {
if (count == 1) {
byte[] midby = new byte[by.length + 1];
midby[0] = mid;
for (int i = 0; i < by.length; i++) {
midby[i + 1] = by[i];
}
by = midby;
count = 0;
}
int num = 0 ;
for (int i = by.length - 1;i>=0;i--) {
if (by[i]<0) {
num++;
}else {
break;
}
}
if (num % 2 == 1) {
str = new String(by, 0, by.length - 1);
count++;
mid = by[by.length - 1];
} else {
str = new String(by, 0, len);
}
System.out.print(str);
}
}
}
欢迎光临 黑马程序员技术交流社区 (http://bbs.itheima.com/)
黑马程序员IT技术论坛 X3.2