3

I have a problem with Netbeans file viewer. I have a string in Arabic that includes accents in top of each letter. When I remove the accents from the string, the letters display correctly. However, when I write the string with the accents, it gets somehow disordered (incorrect).

This is an example of what is happening:

  • Text without accents (correct): بسم الله الرحمن الرحيم
  • Text with accents (incorrect): it shows broken, but if i copy it here it prints correctly
  • It should be like this (correct): بِسْمِ اللَّهِ الرَّحْمَنِ الرَّحِيمِ

The code I wrote is to read a text file that includes an arabic string along with its accents, then write it correctly in a new file, then at the end, it deletes the old file. This is the code:

public void arabicReformer(File disordered) {
    File output = new File("data/temp2.txt");

    try {
        BufferedReader br = new BufferedReader(
                new InputStreamReader(new FileInputStream(disordered), "UTF8"));
        BufferedWriter bw = new BufferedWriter(
                new OutputStreamWriter(new FileOutputStream(output), "UTF8"));
        String line;

        while ((line = br.readLine()) != null) {
            bw.write(line.trim() + "\n");
        }
        br.close();
        bw.close();
    } catch (UnsupportedEncodingException e) {
        System.out.println(e.getMessage());
    } catch (IOException e) {
        System.out.println(e.getMessage());
    } catch (Exception e) {
        System.out.println(e.getMessage());
    }
    output.renameTo(disordered);
}

PS: when I copy past the incorrect arabic string with the accents here, it prints correctly!

3
  • 1
    Did you try with other encoding, UTF-16 for example? stackoverflow.com/questions/2996475/… may be?
    – Praba
    Jul 5, 2015 at 15:25
  • Did you ensure, that your input file is in UTF8 too?
    – knoe
    Jul 5, 2015 at 15:30
  • Unicode can represent an accented letter as one (integrated) symbol, letter-with-accent or two: letter without accent, and zero-width accent. java.text.Normalizer can convert between them. I think letter+accent causes the representation bug. Create a bug report. Maybe RTL/LTR controls already solves the problem.
    – Joop Eggen
    Nov 16, 2021 at 11:23

1 Answer 1

0

Good Day my Friend :) Try using this code to read and print Arabic Characters, and try ensuring that your file is originally in UTF-8.

public void unicodeShow(String fileName) throws UnsupportedEncodingException, FileNotFoundException, IOException{
    Reader reader = new InputStreamReader(new FileInputStream(fileName), "utf-8");
    BufferedReader br = new BufferedReader(reader);
    String a=br.readLine();
    System.out.println(a);
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.