java读取unicode文件_java读取unicode文件

该博客详细介绍了如何使用Java的FileReader读取采用Unicode编码的txt文本文件,每次读取2个字节,确保正确输出编码内容。通过示例代码展示了读取过程,并附有输出结果。
摘要由CSDN通过智能技术生成

主要介绍使用java来读取txt文本文件,且每次读取2个字节,也就是采用unicode编码的文本。

FileMain

package com.test.filetest;

import java.io.File;

import java.io.FileNotFoundException;

import java.io.FileReader;

import java.io.IOException;

public class FileMain {

/**

* @param args

* @throws IOException

*/

public static void main(String[] args) throws IOException {

// TODO Auto-generated method stub

File myfile=new File("H:/test.txt");

//FileReader是字符流,每次读入的是两个字节。

FileReader in=new FileReader(myfile);

int test;

while((test=in.read())!=-1)

{

System.out.println(test);

}

in.close();

}

}

txt文件截图

0818b9ca8b590ca3270a3433284dd417.png

unicode编码

0818b9ca8b590ca3270a3433284dd417.png

输出结果是:

0818b9ca8b590ca3270a3433284dd417.png

我们发现是一样的,也就是可以正常的输出unicode编码。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值