Writing text file that uses UTF8 encoding
I am using
try{
File LogFile =new File("C:\\errotReport1.html");
boolean test = LogFile.exists();
if(test ==false){
FileOutputStream out =new FileOutputStream(LogFile);
p =new OutputStreamWriter(out,"UTF8");
}else{
FileOutputStream out =new FileOutputStream(LogFile);
p =new OutputStreamWriter(out,"UTF8");
}
}catch(Exception e){e.printStackTrace();}
System.err.println("Encoding is " +p.getEncoding());
try{
p.write(new String("Σε απευθείας σύνδεση υπηρεσίες "));
}catch (IOException e){
// TODO Auto-generated catch block
e.printStackTrace();
Where i am going wrong in file it shows only ? instade of my given string
> not getting
No kidding.
>please suggest solution
I suggest a heaping dose of pixie dust and then click your ruby-red slippers together three times while saying
There's no place like home
There's no place like home
There's no place like home
> Where i am going wrong in file it shows only ?
> instade of my given string
What are you using to view the file? If the viewer does not use a font that has glyphs for the characters and/or is not told that the file is utf-8 encoded than you will not see the original.
i have to convert that string into byte array .
I used following
String sourceSegment = "Σε απευθείας σύνδεση υπηρεσίες";
byte[] utf8Bytes = sourceSegment.getBytes("UTF8");
String utf8String = new String
(utf8Bytes, 0, utf8Bytes.length, "UTF8");
targetSegment = currentSegment.getTarget();
byte[] utf8BytesTrg = targetSegment.getBytes("UTF8");
String utf8trgString = new String
(utf8BytesTrg, 0, utf8BytesTrg.length, "UTF8");
i works