Converting a txt File from ANSI to UTF-8 programmatically

后端 未结 1 1418
长发绾君心
长发绾君心 2020-12-11 16:37

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

相关标签:
1条回答
  • 2020-12-11 16:59

    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)
提交回复
热议问题