문제

내 앱에서 아랍어 텍스트를 사용하고 있습니다.시뮬레이터에서 아랍어 텍스트는 괜찮습니다.

그러나 장치에서 올바르게 표시되지 않습니다.

시뮬레이터에서는 مرحبا입니다.

하지만 장치에서는 مرحبا입니다.

나의 필요는이 하나의 مرحبا입니다.

도움이 되었습니까?

해결책

MIDP 응용 프로그램의 텍스트 리소스 및 런타임에로드하는 방법을 만듭니다. 이 기술은 유니 코드 안전이므로 모든 언어에 적합합니다. 런타임 코드는 작고 빠르며 비교적 작은 메모리를 사용합니다.

텍스트 소스 생성

اَللّٰهُمَّ اِنِّىْ اَسْئَلُكَ رِزْقًاوَّاسِعًاطَيِّبًامِنْ رِزْقِكَ
مَرْحَبًا
.

프로세스는 텍스트 파일을 만드는 것으로 시작합니다. 파일이로드되면 각 행은 별도의 문자열 객체가되므로 다음과 같은 파일을 만들 수 있습니다.

이것은 UTF-8 형식이어야합니다. Windows에서는 메모장에서 UTF-8 파일을 만들 수 있습니다. 다른 이름으로 저장 ...을 사용하고 UTF-8 인코딩을 선택하십시오.

여기에 이미지 설명을 입력하십시오

arb.utf8 라는 이름을 만든다.

MIDP 응용 프로그램에서 쉽게 읽을 수있는 형식으로 변환해야합니다. MIDP는 J2SE 버퍼 디더와 같은 텍스트 파일을 읽는 편리한 방법을 제공하지 않습니다. 유니 코드 지원은 바이트와 문자를 변환 할 때 문제가 될 수도 있습니다. 텍스트를 읽는 가장 쉬운 방법은 datainput.readutf ()를 사용하는 것입니다. 그러나이 기능을 사용하려면 DataOutput.WriteUTF ()를 사용하여 텍스트를 작성해야합니다.

아래의

메모장에서 저장 한 .uft8 파일을 읽는 단순 J2SE, 명령 줄 프로그램은 JAR에서 이동할 수있는 파일을 만듭니다.

import java.io.*;
import java.util.*;

public class TextConverter {

    public static void main(String[] args) {
        if (args.length == 1) {
            String language = args[0];

            List<String> text = new Vector<String>();

            try {
                // read text from Notepad UTF-8 file
                InputStream in = new FileInputStream(language + ".utf8");
                try {
                    BufferedReader bufin = new BufferedReader(new InputStreamReader(in, "UTF-8"));
                    String s;
                    while ( (s = bufin.readLine()) != null ) {
                        // remove formatting character added by Notepad
                        s = s.replaceAll("\ufffe", "");
                        text.add(s);
                    }
                } finally {
                    in.close();
                }

                // write it for easy reading in J2ME
                OutputStream out = new FileOutputStream(language + ".res");
                DataOutputStream dout = new DataOutputStream(out);
                try {
                    // first item is the number of strings
                    dout.writeShort(text.size());
                    // then the string themselves
                    for (String s: text) {
                        dout.writeUTF(s);
                    }
                } finally {
                    dout.close();
                }
            } catch (Exception e) {
                System.err.println("TextConverter: " + e);
            }
        } else {
            System.err.println("syntax: TextConverter <language-code>");
        }
    }
}
.

arb.utf8을 arb.res로 변환하려면 다음과 같이 변환기를 실행하십시오.

java TextConverter arb
.

런타임에 텍스트 사용

.res 파일을 JAR에 놓습니다.

MIDP 응용 프로그램 에서이 방법으로 텍스트를 읽을 수 있습니다.

  public String[] loadText(String resName) throws IOException {
    String[] text;
    InputStream in = getClass().getResourceAsStream(resName);
    try {
        DataInputStream din = new DataInputStream(in);
        int size = din.readShort();
        text = new String[size];
        for (int i = 0; i < size; i++) {
            text[i] = din.readUTF();
        }
    } finally {
        in.close();
    }
    return text;
}
.

텍스트를 다음과 같이로드하고 사용하십시오.

String[] text = loadText("arb.res");
System.out.println("my arabic word from arb.res file ::"+text[0]+" second from arb.res file ::"+text[1]);
.

이것이 당신을 도울 것입니다. 감사합니다

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top