简体   繁体   中英

ASCII to UTF-8 conversion in java

i have a problem which i uploaded data using .CSV file format and it read by java class.and i would be store in db.upto now no problem,but when i read the data from db then data contains some special characters.

so please could you help me here

Thanks in advance.

ASCII-7 is compatible with UTF-8. There is nothing you need to do turn turn ASCII-7 into UTF-8 (but it doesn't work the other way)

This is an article you should really read.

The Absolute Minimum Every Software Developer Absolutely, Positively Must Know About Unicode and Character Sets (No Excuses!)

Next, to answer your question:

  • To Read a file encoded with UTF-8, use a BufferedReader :

     BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream(file), "UTF-8")); 
  • To Write a file encoded with UTF-8 use a BufferedWriter :

     BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(file), "UTF-8")); 

Make sure that the transmittion of the data through the sockets goes correct.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM