当前位置:网站首页>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
边栏推荐
- Scratch colorful candied haws Electronic Society graphical programming scratch grade examination level 3 true questions and answers analysis June 2022
- PHP talent recruitment system development source code recruitment website source code secondary development
- [61dctf]fm
- Allusions of King Xuan of Qi Dynasty
- Google Earth Engine(GEE)——Kernel核函数简单介绍以及灰度共生矩阵
- [wechat applet] read the life cycle and route jump of the applet
- 數據訪問 - EntityFramework集成
- Solve cmakelist find_ Package cannot find Qt5, ECM cannot be found
- 调查显示传统数据安全工具面对勒索软件攻击的失败率高达 60%
- Jarvis OJ shell traffic analysis
猜你喜欢

Games101 notes (I)

Pspnet | semantic segmentation and scene analysis

If you can't afford a real cat, you can use code to suck cats -unity particles to draw cats

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

干货!半监督预训练对话模型 SPACE
![[brush title] goose factory shirt problem](/img/c8/44496c767a778101cf3982bd911933.png)
[brush title] goose factory shirt problem

国内首家 EMQ 加入亚马逊云科技「初创加速-全球合作伙伴网络计划」

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

Jarvis OJ Flag

如何安装mysql
随机推荐
PHP 严格模式
PHP strict mode
BS-XX-042 基于SSM实现人事管理系统
American chips are no longer proud, and Chinese chips have successfully won the first place in emerging fields
【剑指 Offer】61. 扑克牌中的顺子
Explain in detail the functions and underlying implementation logic of the groups sets statement in SQL
Apple has abandoned navigationview and used navigationstack and navigationsplitview to implement swiftui navigation
sqlserver 做cdc 要对数据库性能有什么要求么
Practical example of propeller easydl: automatic scratch recognition of industrial parts
Do sqlserver have any requirements for database performance when doing CDC
Jarvis OJ shell traffic analysis
Etcd build a highly available etcd cluster
Precision epidemic prevention has a "sharp weapon" | smart core helps digital sentinels escort the resumption of the city
How to uninstall MySQL cleanly
npm安装
How does the outer disk futures platform distinguish formal security?
[729. My Schedule i]
Sentinel-流量防卫兵
Data verification before and after JSON to map -- custom UDF
启牛商学院股票开户安全吗?靠谱吗?