Java: Unicode Bidirectional Text

Posted on 2009-12-22
Last Modified: 2012-05-08
Hi Experts,

I need your help, I have a text file (code page = Windows-1255) and I need to convert it to unicode (UTF-8) to be processed by our system.

I used the method in the attached  code to do the conversion: (VB.Net)

the conversion create problem because some lines can have one part that is right-to-left and another can be left-to-right. (and the Hebrow words will be written in reverse order!)

anyhow, I know there is a Java class that is supposed to solve this problem and all I need is an example of how to use this class to covert a text file.

this is the class : java.text.Bidi[],%20int,%20java.lang.Object[],%20int,%20int%29

I will appreciate any solution to this problem using either .Net or Java.




public void Convert1255toUnicode(){

        //open ASCII text file and read it using Windows-1255 code page into a UTF-8 string

        using (System.IO.StreamReader s = new System.IO.StreamReader("c:\\temp\\AsciiInputFile.txt", System.Text.Encoding.GetEncoding("Windows-1255"), true))


            string  utf8string = s.ReadToEnd();

            //Write the string into a Unicode file

            Microsoft.VisualBasic.FileIO.FileSystem.WriteAllText("c:\\temp\\UnicodeOutputFile.txt", utf8string, false, System.Text.Encoding.Unicode);



Open in new window

Question by:Misbah
    LVL 9

    Accepted Solution

    LVL 5

    Expert Comment

    This is my Java version for your reference.

    public void Convert1255toUnicode()
    	BufferedReader reader = null;
    	PrintStream writer = null;
    		// Prepare a reader to read the contents from a Windows-1255 code page
    		reader = new BufferedReader(new InputStreamReader(new FileInputStream("c:\\temp\\AsciiInputFile.txt"), "windows-1255"));
    		// Prepare a writer to write the contents to a UTF-8 file
    		writer = new PrintStream(new FileOutputStream("c:\\temp\\UnicodeOutputFile.txt"), true, "UTF-8");
    		// Loop to read each line from the Windows-1255 code page
    		for (String line = null; (line = reader.readLine()) != null; )
    			//Write the string into a Unicode file
    	// Close reader/write, and do a graceful exit.
    		if (reader != null)
    			try {
    			} finally {}
    		if (writer != null)
    			try {
    			} finally {}

    Open in new window


    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Better Security Awareness With Threat Intelligence

    See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

    More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
    Java functions are among the best things for programmers to work with as Java sites can be very easy to read and prepare. Java especially simplifies many processes in the coding industry as it helps integrate many forms of technology and different d…
    Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…
    This video teaches viewers about errors in exception handling.

    794 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    15 Experts available now in Live!

    Get 1:1 Help Now