java - How do I convert List<String[]> values from UTF-8 to String? -
I want to convert some Greek text from string to UTF-8, because they can not be recognized by Java is. Then, I want to populate them in a jetty. So I use the list to help me I have the code snippet:
string [] [] rowData; & Lt; String [] & gt; MyEntries; // ... try {this.fileReader = new FileReader ("D: \\ Book1.csv"); This.reader = New CSVReader (fileReader, ';'); MyEntries = reader.readAll (); // Here I want to change every value from UTF-8 to string converts 8 (myEntries); // ??? This.rowData = myEntries.toArray (new string [0] []); } Hold (FileNotFoundException pre) {Logger.getLogger (VJTable.class.getName ()). Logs (level. SESEE, ANNEL, X); } Hold (IOException pre) {Logger.getLogger (VJTable.class.getName ()). Log (Level.SEVERE, null, ex); } // <...
I have created a method
public string convert format (list & lt; string [] & gt; s) String out = null; {String string stratus: s) {try out {new string (s.getBytes ("ISO-8859-1"), "UTF-8"); }} Hold (java.io.UnsupportedEncodingException e) {return tap; } Exit; }
But I can not continue because there is no getBytes () method for the list. What should I do. Any ideas would be very helpful thanks in advance.
The problem is the use of your FileReader
which only sets the "default" character set Supports:
this.fileReader = new FileReader ("D: \\ Book1.csv");
The javadoc is very clear for this:
Constructors of this class assume that the default character encoding and default byte buffer sizes are appropriate. To specify these values in itself, create an input stream reader on a file inputstreet.
The proper way to get a reader
with a character set specified is as follows:
this.fileStream = New FileInputStream ("D: \\ Book1.csv"); This.fileReader = New InputStreamReader (file stream, "utf-8");
Comments
Post a Comment