java - Unexpected result when writing a Unicode(UTF-8) text to file -
i have problem when writing unicode(utf-8) text file java. want writ text in other language (persian) file in java, receive unexpected result after run app.
file file = new file(outputfilename); fileoutputstream f = new fileoutputstream(outputfilename); string encoding = "utf-8"; outputstreamwriter osw = new outputstreamwriter(f,encoding); bufferedwriter bw = new bufferedwriter(osw); stringbuilder row = new stringbuilder(); row.append("some text in english language"); // in below code should 4 space before علی row.append(" علی"); // in below code should 6 space before علی یاری row.append(" علی یاری"); bw.write(row.tostring()); bw.flush(); bw.close();
how can solve problem?
the output expected according unicode bidirectional algorithm. entire persian text rendered right-to-left. if want individual words laid out left-to-right, need insert left-to-right character between 2 persian words. there's special character this: left right mark (u+200e). modification code should produce correct output:
row.append("some text in english language"); row.append(" علی"); row.append('\u200e'); row.append(" علی یاری");
Comments
Post a Comment