java txt ansi,将txt文件从ANSI转换为UTF-8,以编程方式

该博客探讨了如何处理ANSI编码的文本文件,当尝试将其数据写入数据库时遇到的乱码问题。解决方案涉及到使用特定的Java Reader进行解码,如InputStreamReader,并指定正确的字符集(如windows-1252)。同时,正确配置数据库和JDBC驱动也是确保数据正确写入的关键。
摘要由CSDN通过智能技术生成

I need your help here please.

I'm working on a java application that convert data from a txt file into the database , The problem is that the file have ANSI encoding which i can't change because it comes from outside my application ,and when i write the data to the database i got some "???" inside.

My question is , how can i convert the data that i read from the file from ANSI to UTF-8 which can handle those weired symbols.

I've tried the Byte[] to String converting but it didn't work.

解决方案

Use open a decoding Reader like this one:

Reader reader =

new InputStreamReader(inputStream, Charset.forName(encodingName));

Exaclty which encoding name you should use depends on which "ANSI" encoding the text file was written in. You can find a list of encoding supported by Java 6 here. If it is an English-language system, it will likely be windows-1252.

Writing data to the database correctly depends on configuring the database correctly and (sometimes) providing the right configuration to the JDBC driver.

You can read more about character encoding handling in here and here.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值