08-12-2010 03:06 PM
I have developed a MIDLET which involves reading of Files and storing the contents of the files in arrays. I was able to do this using FileConnection API in J2ME (Java ME) and it works fine in the mobile emulators provided by Sun, Sun Wireless Tool Kit 2.5.1 and Sprint Wireless Tool Kit 3.3.2. I have been using netbeans 6.8 IDE for this.
Now, here is the deal. The reading of files does not work when in any of the Blackberry mobile emulators. i have tried installing all the versions of Blackberry JDE from 4.2.1 to 5.0 and testing the same, but none of them worked. Having read the Blackberry plugin for Eclipse is good, i used it only to find that i am still facing the problem.
I am in desperate need of help. Can someone help me to make the file reading work in a Blackberry emulator ? I am inserting the code which performs file reading. It reads a file containing a single column of 60 entries and stores it in a array of type double.
Vector time = new Vector();
FileConnection filecon = (FileConnection) Connector.open("file:///" +
Dialog.show("Note ! ", "File doesn't exists !", "okay","cancel");
StringBuffer sb = new StringBuffer();
InputStream in = filecon.openInputStream();
while ((chars = in.read()) != -1)// read until EOF is reached
if(chars == '\n') // read all characters until the end of line is reached
time.addElement(sb.toString().trim()); // stores all the characters as a vector element when the end of line is reached
sb.delete(0,sb.length());// clear the stringbuffer for storing the next line of the file
sb.append((char)chars); // appends each character read
}// end of while
}// end of outer try
int i =0;
Enumeration etime = time.elements();
while(etime.hasMoreElements() && i < 60) // timescale.dat has 60 entries in one column
toString());// convert to double
Solved! Go to Solution.
08-16-2010 02:35 PM
Can you elaborate on what is not working? Is any error or exception thrown? If so what is it and what line of code triggers it?
Have you configured the BlackBerry smartphone simulator to simulate a micro SD card?
Use a computer file system as a microSD card
08-16-2010 06:43 PM - edited 08-17-2010 03:47 PM
That was really helpful. But, i did not get any kind of error or exception when i ran my MIDlet. But, to use a PC file as a SDCard, i used the option (Simulate -> Change SD Card) when the Blackberry emulator showed up after i ran the application. Now, i am getting my MIDlet to read files using BlackBerry Bold 9700 Simulator.
08-17-2010 10:02 AM
There should have been an IOException thrown. But your code is catching it without logging the error, so you would only see it if you stepped through the code while debugging.