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. New to the forum? Please visit the ‘Getting Started’ link below.
inside custom component

Java Development

Reply
Trusted Contributor
babyblue_lee
Posts: 130
Registered: ‎08-10-2010
Accepted Solution

File I/O on local

Hi,

 

I'm trying to record some of the runtime logs on my local machine.

But I found I cannot use FileOutputStream, since I cannot import JRE6 once BlackBerry JRE 5.0 is imported. (It would cause error while compiling.)

 

Is there any easy way to write into files on local, in a class that is extended from UiApplication?

Please use plain text.
Trusted Contributor
babyblue_lee
Posts: 130
Registered: ‎08-10-2010

Re: File I/O on local

BTW, I cannot use System.out.println() to print some information to console.

 

Is there any way to do so? Thanks.

Please use plain text.
Developer
peter_strange
Posts: 17,713
Registered: ‎07-14-2008

Re: File I/O on local

Not clear on what you are trying to do. 

 

Remember that the code you write for a Blackberry runs on a BlackBerry, which is completely independent of any PC.  SO you are not going to be able to do I/O to your PC's file system - the BlackBerry does not know about it.  There are a few tricks that the Simulator pulls to make life easier for you when developing.

 

Regarding Blackberry specific class for logging, look at EventLogger. 

Please use plain text.
Trusted Contributor
babyblue_lee
Posts: 130
Registered: ‎08-10-2010

Re: File I/O on local

Thanks. I'm going to try this way.

Please use plain text.
Developer
BB-Dude
Posts: 516
Registered: ‎07-23-2010

Re: File I/O on local

You can also use a local directory as your SDCard and you can write a file using

javax.microedition.io.file package.

Please use plain text.
Developer
peter_strange
Posts: 17,713
Registered: ‎07-14-2008

Re: File I/O on local

"You can also use a local directory as your SDCard"

 

One of the tricks that the Simulator pulls.  Remember that logging to the SD Card assumes that the user has an SD Card and that there is space and that they don't have anything else in the same place.  I must admit I have resisted doing this.  But it does work!

Please use plain text.
Developer
BB-Dude
Posts: 516
Registered: ‎07-23-2010

Re: File I/O on local

I agree with you to a certain degree Peter. But I usually give the user the option to choose where to save the log file. Either in the persistent store, SDCard, or local memory. It's easier to email the log as attachment when it's in the file system.

Please use plain text.
Developer
peter_strange
Posts: 17,713
Registered: ‎07-14-2008

Re: File I/O on local

Excellent implementation BB-Dude! 

Please use plain text.
Trusted Contributor
babyblue_lee
Posts: 130
Registered: ‎08-10-2010

Re: File I/O on local

Thanks guys! It helps a lot.

Please use plain text.
Trusted Contributor
babyblue_lee
Posts: 130
Registered: ‎08-10-2010

Re: File I/O on local

Hi BB-Dude,

 

Would you please give an example on how to use thejavax.microedition.io.file.* to write a file on SD card?

Thanks!

Please use plain text.