当前位置:网站首页>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
边栏推荐
- [team PK competition] the task of this week has been opened | question answering challenge to consolidate the knowledge of commodity details
- Learnopongl notes (II) - Lighting
- Sentinel flow guard
- Flet tutorial 12 stack overlapping to build a basic introduction to graphic and text mixing (tutorial includes source code)
- If you can't afford a real cat, you can use code to suck cats -unity particles to draw cats
- 高数 | 旋转体体积计算方法汇总、二重积分计算旋转体体积
- Explain in detail the functions and underlying implementation logic of the groups sets statement in SQL
- Basic introduction to the control of the row component displaying its children in the horizontal array (tutorial includes source code)
- Is it safe to open a securities account by mobile phone? Detailed steps of how to buy stocks
- 数据访问 - EntityFramework集成
猜你喜欢

【刷題篇】鹅廠文化衫問題

Wsl2.0 installation

Summary of PHP pseudo protocol of cisp-pte

How was the middle table destroyed?

Domestic API management artifact used by the company

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

Clear restore the scene 31 years ago, volcanic engine ultra clear repair beyond classic concert

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

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

The survey shows that the failure rate of traditional data security tools in the face of blackmail software attacks is as high as 60%
随机推荐
Jarvis OJ webshell analysis
如何安装mysql
[729. My Schedule i]
Learnopongl notes (I)
Do sqlserver have any requirements for database performance when doing CDC
Browser rendering principle and rearrangement and redrawing
美国芯片傲不起来了,中国芯片成功在新兴领域夺得第一名
Data access - entityframework integration
【微信小程序】一文读懂小程序的生命周期和路由跳转
Sentinel flow guard
挖财股票开户安全吗?怎么开股票账户是安全?
BS-XX-042 基于SSM实现人事管理系统
Jarvis OJ Telnet Protocol
Jarvis OJ simple network management protocol
Is it safe to open a securities account by mobile phone? Detailed steps of how to buy stocks
为季前卡牌游戏 MotoGP Ignition Champions 做好准备!
Deep learning plus
[brush title] goose factory shirt problem
The two ways of domestic chip industry chain go hand in hand. ASML really panicked and increased cooperation on a large scale
China Radio and television officially launched 5g services, and China Mobile quickly launched free services to retain users