使用扫描仪读取utf-8 [英] Read utf-8 using Scanner

查看:124
本文介绍了使用扫描仪读取utf-8的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用 扫描仪 时,我遇到UTF-8编码问题。我的数据文件的两行示例:

I am having trouble with UTF-8 encoding when using Scanner. Example two lines of my data file:

000001 Mėlynas Tadas 63210309683 V 2003/03/17 2016/03/17 
000002 Raudonas Tomas 65505023282 V 2006/01/26 2018/01/26

目前我正在使用 扫描仪 可以单独阅读文本,而不是整行,因为这样更方便,但由于编码而无法正确读取。我已经阅读了关于使用 InputStream 等等,但我不想处理凌乱的线斩。有没有办法使用UTF-8的 扫描仪

Currently I am using Scanner to read the text separately instead of the whole line as this is more convenient, but it doesn't read correctly because of the encoding. I've read about using InputStream etc but I don't want to deal with messy line chopping. Is there a way to use Scanner with UTF-8?

推荐答案

此代码片段可能有助于:

This code snippet might help:

Locale loc = new Locale("es", "ES");
Scanner sc = new Scanner(new FileInputStream(file), "UTF-8");
sc.useLocale(loc);

这篇关于使用扫描仪读取utf-8的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆