Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Create text resources for a MIDP application, and how to load them at run-time. This technique is unicode safe, and so is suitable for all languages. The run-time code is small, fast, and uses relatively little memory.</p> <p>Creating the Text Source</p> <pre><code>اَللّٰهُمَّ اِنِّىْ اَسْئَلُكَ رِزْقًاوَّاسِعًاطَيِّبًامِنْ رِزْقِكَ مَرْحَبًا </code></pre> <p>The process starts with creating a text file. When the file is loaded, each line becomes a separate String object, so you can create a file like:</p> <p>This needs to be in UTF-8 format. On Windows, you can create UTF-8 files in Notepad. Make sure you use Save As..., and select UTF-8 encoding.</p> <p><img src="https://i.stack.imgur.com/06t54.png" alt="enter image description here"></p> <p>Make the name arb.utf8</p> <p>This needs to be converted to a format that can be read easily by the MIDP application. MIDP does not provide convenient ways to read text files, like J2SE's BufferedReader. Unicode support can also be a problem when converting between bytes and characters. The easiest way to read text is to use DataInput.readUTF(). But to use this, we need to have written the text using DataOutput.writeUTF().</p> <p>Below is a simple J2SE, command-line program that will read the .uft8 file you saved from notepad, and create a .res file to go in the JAR.</p> <pre><code>import java.io.*; import java.util.*; public class TextConverter { public static void main(String[] args) { if (args.length == 1) { String language = args[0]; List&lt;String&gt; text = new Vector&lt;String&gt;(); 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 &lt;language-code&gt;"); } } } </code></pre> <p>To convert arb.utf8 to arb.res, run the converter as:</p> <pre><code>java TextConverter arb </code></pre> <p>Using the Text at Runtime</p> <p>Place the .res file in the JAR. </p> <p>In the MIDP application, the text can be read with this method:</p> <pre><code> 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 &lt; size; i++) { text[i] = din.readUTF(); } } finally { in.close(); } return text; } </code></pre> <p>Load and use text like this:</p> <pre><code>String[] text = loadText("arb.res"); System.out.println("my arabic word from arb.res file ::"+text[0]+" second from arb.res file ::"+text[1]); </code></pre> <p>Hope this will help you. Thanks</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload