当前位置:网站首页>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
边栏推荐
猜你喜欢
China Radio and television officially launched 5g services, and China Mobile quickly launched free services to retain users
【Web攻防】WAF检测技术图谱
Data access - entityframework integration
Benji Bananas 会员通行证持有人第二季奖励活动更新一览
Scratch colorful candied haws Electronic Society graphical programming scratch grade examination level 3 true questions and answers analysis June 2022
深耕5G,芯讯通持续推动5G应用百花齐放
NPM installation
Jarvis OJ Telnet Protocol
BS-XX-042 基于SSM实现人事管理系统
Pspnet | semantic segmentation and scene analysis
随机推荐
如何安装mysql
Get ready for the pre-season card game MotoGP ignition champions!
国产芯片产业链两条路齐头并进,ASML真慌了而大举加大合作力度
Accès aux données - intégration du cadre d'entité
为季前卡牌游戏 MotoGP Ignition Champions 做好准备!
网站页面禁止复制内容 JS代码
Jarvis OJ 远程登录协议
Browser rendering principle and rearrangement and redrawing
Copy mode DMA
数据访问 - EntityFramework集成
The first EMQ in China joined Amazon cloud technology's "startup acceleration - global partner network program"
[729. My schedule I]
[es6] add if judgment or ternary operator judgment in the template string
Pspnet | semantic segmentation and scene analysis
How does the outer disk futures platform distinguish formal security?
Jarvis OJ webshell analysis
Error in composer installation: no composer lock file present.
Binary tree related OJ problems
[61dctf]fm
Solution of vant tabbar blocking content