san
san

Reputation: 49

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.

Upvotes: 3

Views: 5778

Answers (2)

Martijn Courteaux
Martijn Courteaux

Reputation: 68907

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.

Upvotes: 0

Peter Lawrey
Peter Lawrey

Reputation: 533880

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)

Upvotes: 4

Related Questions