Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Java Development

Reply
New Contributor
srikanth_kannan
Posts: 6
Registered: ‎07-21-2010
My Device: Not Specified
Accepted Solution

problem using FileConnection API (JSR 75) in a MIDLET application for Blackberry Bold

Hi,

 

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();

try
{

FileConnection filecon = (FileConnection) Connector.open("file:///" +
"SDCard/BlackBerry/documents/"+"timescale.dat");

if(!filecon.exists())
{
Dialog.show("Note ! ", "File doesn't exists !", "okay","cancel");
}

StringBuffer sb = new StringBuffer();
try
{
InputStream in = filecon.openInputStream();
int chars;

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

}

else
{
sb.append((char)chars); // appends each character read
}

}// end of while

}
catch(IOException e)
{
}

filecon.close();

}// end of outer try

int i =0;
Enumeration etime = time.elements();

while(etime.hasMoreElements() && i < 60) // timescale.dat has 60 entries in one column
{
time_1d[i]=Double.parseDouble(etime.nextElement().toString());// convert to double
i++;
}

 

 

Please use plain text.
BlackBerry Development Advisor
MSohm
Posts: 14,685
Registered: ‎07-09-2008
My Device: BlackBerry Z30, BlackBerry PlayBook

Re: problem using FileConnection API (JSR 75) in a MIDLET application for Blackberry Bold

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

http://supportforums.blackberry.com/t5/Testing-and-Deployment/Use-a-computer-file-system-as-a-microS...

Mark Sohm
BlackBerry Development Advisor

Please refrain from posting new questions in solved threads.
Problem solved? Click the Accept As Solution button.
Found a bug? Report it using Issue Tracker
Please use plain text.
New Contributor
srikanth_kannan
Posts: 6
Registered: ‎07-21-2010
My Device: Not Specified

Re: problem using FileConnection API (JSR 75) in a MIDLET application for Blackberry Bold

[ Edited ]

Thanks Mark,

 

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.

Please use plain text.
BlackBerry Development Advisor
MSohm
Posts: 14,685
Registered: ‎07-09-2008
My Device: BlackBerry Z30, BlackBerry PlayBook

Re: problem using FileConnection API (JSR 75) in a MIDLET application for Blackberry Bold

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.

Mark Sohm
BlackBerry Development Advisor

Please refrain from posting new questions in solved threads.
Problem solved? Click the Accept As Solution button.
Found a bug? Report it using Issue Tracker
Please use plain text.