当前位置:网站首页>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
边栏推荐
- Pspnet | semantic segmentation and scene analysis
- Global Data Center released DC brain system, enabling intelligent operation and management through science and technology
- 【剑指 Offer】61. 扑克牌中的顺子
- 中国广电正式推出5G服务,中国移动赶紧推出免费服务挽留用户
- [echart] resize lodash to realize chart adaptation when window is zoomed
- Raspberry pie 4B installation pytorch1.11
- [brush questions] effective Sudoku
- WSL2.0安装
- Precision epidemic prevention has a "sharp weapon" | smart core helps digital sentinels escort the resumption of the city
- SQL injection of cisp-pte (Application of secondary injection)
猜你喜欢

Android 隐私沙盒开发者预览版 3: 隐私安全和个性化体验全都要

How to set the WiFi password of the router on the computer

中国广电正式推出5G服务,中国移动赶紧推出免费服务挽留用户

二叉树相关OJ题

Etcd 构建高可用Etcd集群

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

如何安装mysql

Jarvis OJ shell traffic analysis

The survey shows that the failure rate of traditional data security tools in the face of blackmail software attacks is as high as 60%

Keras crash Guide
随机推荐
How does win11 change icons for applications? Win11 method of changing icons for applications
面对新的挑战,成为更好的自己--进击的技术er
【组队 PK 赛】本周任务已开启 | 答题挑战,夯实商品详情知识
Jarvis OJ Webshell分析
composer安装报错:No composer.lock file present.
Jarvis OJ shell traffic analysis
Jarvis OJ Flag
Basic introduction to the control of the row component displaying its children in the horizontal array (tutorial includes source code)
Sentinel-流量防卫兵
Error in composer installation: no composer lock file present.
What is the difference between EDI license and ICP business license
C# TCP如何设置心跳数据包,才显得优雅呢?
Sentinel flow guard
阈值同态加密在隐私计算中的应用:解读
PHP talent recruitment system development source code recruitment website source code secondary development
浏览器渲染原理以及重排与重绘
【刷题篇】鹅厂文化衫问题
Deep learning plus
tf. sequence_ Mask function explanation case
[echart] resize lodash to realize chart adaptation when window is zoomed