当前位置:网站首页>Use byte stream to read Chinese from file to console display
Use byte stream to read Chinese from file to console display
2022-07-05 17:01:00 【Oh-liuxing】
package text;
import java.io.FileInputStream;
import java.io.IOException;
public class FileInputStreamDemo06 {
public static void main(String[] args) throws IOException {
FileInputStream fis = new FileInputStream("D:\\a.txt");
int len;
byte[] bytes = new byte[70];
while ((len = fis.read(bytes)) != -1) {
System.out.print(new String(bytes, 0, len, "gbk"));
}
fis.close();
}
}
Tips :idea By default utf-8 Coded ,utf-8 code 1 Chinese accounts for 3 Bytes ,gbk code 1 Chinese accounts for 2 Bytes . Using byte stream to read Chinese data adopts the method of reading one byte at a time , So what you read is garbled . When we use Notepad to store Chinese, the default is ANSI code , In fact, that is GBK code
边栏推荐
- The first EMQ in China joined Amazon cloud technology's "startup acceleration - global partner network program"
- 面对新的挑战,成为更好的自己--进击的技术er
- Etcd build a highly available etcd cluster
- 挖财股票开户安全吗?怎么开股票账户是安全?
- Benji Bananas 会员通行证持有人第二季奖励活动更新一览
- PHP talent recruitment system development source code recruitment website source code secondary development
- Wechat official account web page authorization login is so simple
- 飞桨EasyDL实操范例:工业零件划痕自动识别
- Writing method of twig array merging
- Bs-xx-042 implementation of personnel management system based on SSM
猜你喜欢

文件操作--I/O

解决CMakeList find_package找不到Qt5,找不到ECM

Global Data Center released DC brain system, enabling intelligent operation and management through science and technology

Solve cmakelist find_ Package cannot find Qt5, ECM cannot be found

美国芯片傲不起来了,中国芯片成功在新兴领域夺得第一名

Copy mode DMA

Keras crash Guide

WSL2.0安装

Detailed explanation of use scenarios and functions of polar coordinate sector diagram

npm安装
随机推荐
Is it safe to open a securities account by mobile phone? Detailed steps of how to buy stocks
树莓派4b安装Pytorch1.11
"21 days proficient in typescript-3" - install and build a typescript development environment md
微信公众号网页授权登录实现起来如此简单
麻烦问下,DMS中使用Redis语法是以云数据库Redis社区版的命令为参考的嘛
【729. 我的日程安排表 I】
采用药丸屏的iPhone14或引发中国消费者的热烈抢购
Jarvis OJ Webshell分析
Sentinel-流量防卫兵
【剑指 Offer】63. 股票的最大利润
【Web攻防】WAF检测技术图谱
The survey shows that the failure rate of traditional data security tools in the face of blackmail software attacks is as high as 60%
文件操作--I/O
Copy mode DMA
How does the outer disk futures platform distinguish formal security?
Facing new challenges and becoming a better self -- attacking technology er
【剑指 Offer】66. 构建乘积数组
Detailed explanation of use scenarios and functions of polar coordinate sector diagram
How to uninstall MySQL cleanly
[wechat applet] read the life cycle and route jump of the applet