File reading issues in Nokia Asha 303
Hi,
I am reading a fixed number of characters from a file. The file contains both english and arabic text. I have two devices Nokia X3-02 and Nokia Asha 303 for testing. On Nokia X3-02, I am getting the correct string that I require from the file in every case. But on Asha 303, I do not get the complete string when the string contains some arabic character.
I have also tested my code on the sun emulator and it is working fine on it too. The issue seams to be with Nokia Asha 303 device only.
My code is a very simple one in which I read a file by specifying the reading position (Offset) and the length to be read. Please help me as I do not understand this problem.
Re: File reading issues in Nokia Asha 303
Hi abdul.wahab,
This might be code related or software related. After some testing on Nokia 303 with software version 14.60, I was able to display on the screen a file that contained this String: "Some info يتس in Arabic" with this code:
[CODE]
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import javax.microedition.io.Connector;
import javax.microedition.io.file.FileConnection;
import javax.microedition.lcdui.Display;
import javax.microedition.lcdui.Form;
import javax.microedition.midlet.MIDlet;
import javax.microedition.midlet.MIDletStateChangeException;
public class FileReadTextMIDlet extends MIDlet {
protected void destroyApp(boolean arg0) throws MIDletStateChangeException {
// TODO Auto-generated method stub
}
protected void pauseApp() {
// TODO Auto-generated method stub
}
protected void startApp() throws MIDletStateChangeException {
Form mainForm = new Form("Arabic File Read");
Display.getDisplay(this).setCurrent(mainForm);
try {
String filepath = System.getProperty("fileconn.dir.memorycard") + "testapp/test.txt";
FileConnection fconn = (FileConnection)Connector.open(filepath);
InputStream is = fconn.openInputStream();
int size = is.available();
InputStreamReader isr = new InputStreamReader(is, "UTF8");
char[] data = new char[size];
isr.read(data);
String output = new String(data);
mainForm.append(output);
is.close();
fconn.close();
}
catch (IOException ioe) {
System.out.println(ioe.getMessage());
}
}
}
[/CODE]
The text file should be placed in the memory card, under the path testapp/text.txt. Could you try again with this code? It might be that you need to update your device's software.
Re: File reading issues in Nokia Asha 303
Thanks skalogir
I have managed to solve the issue. On Nokia x3-02 the app was reading the exact number of characters as specified in the read function of InputStreamReader but on Nokia Asha 303, the characters read were always less than the ones specified. So I had to loop the read function in order to read all characters. Now it is working on Nokia Asha 303.