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.
Try Settings -> Preferences -> New document -> Encoding -> choose UTF-8 without BOM, and check Apply to opened ANSI files . That way all the opened ANSI files will be treated as UTF-8 without BOM.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With