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

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.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值