当前位置:网站首页>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
边栏推荐
- 外盘期货平台如何辨别正规安全?
- 【729. 我的日程安排表 I】
- 【剑指 Offer】62. 圆圈中最后剩下的数字
- 启牛商学院股票开户安全吗?靠谱吗?
- 兰空图床苹果快捷指令
- BS-XX-042 基于SSM实现人事管理系统
- Detailed explanation of use scenarios and functions of polar coordinate sector diagram
- China Radio and television officially launched 5g services, and China Mobile quickly launched free services to retain users
- 网站页面禁止复制内容 JS代码
- 调查显示传统数据安全工具面对勒索软件攻击的失败率高达 60%
猜你喜欢

dried food! Semi supervised pre training dialogue model space

Win11 prompt: what if the software cannot be downloaded safely? Win11 cannot download software safely

兰空图床苹果快捷指令

干货!半监督预训练对话模型 SPACE

Learnopongl notes (II) - Lighting

Hiengine: comparable to the local cloud native memory database engine

Games101 notes (II)

【729. 我的日程安排表 I】

Fleet tutorial 09 basic introduction to navigationrail (tutorial includes source code)

文件操作--I/O
随机推荐
composer安装报错:No composer.lock file present.
【剑指 Offer】63. 股票的最大利润
It is forbidden to copy content JS code on the website page
ECU introduction
二叉树相关OJ题
The first EMQ in China joined Amazon cloud technology's "startup acceleration - global partner network program"
【剑指 Offer】66. 构建乘积数组
Browser rendering principle and rearrangement and redrawing
国产芯片产业链两条路齐头并进,ASML真慌了而大举加大合作力度
Jarvis OJ Webshell分析
Android 隐私沙盒开发者预览版 3: 隐私安全和个性化体验全都要
[deep learning] [original] let yolov6-0.1.0 support the txt reading dataset mode of yolov5
Jarvis OJ webshell analysis
PHP talent recruitment system development source code recruitment website source code secondary development
关于new Map( )还有哪些是你不知道的
Solution of vant tabbar blocking content
微信公众号网页授权登录实现起来如此简单
Jarvis OJ simple network management protocol
飞桨EasyDL实操范例:工业零件划痕自动识别
How does win11 change icons for applications? Win11 method of changing icons for applications