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
Developer
Posts: 54
Registered: ‎05-28-2009
My Device: Not Specified
Accepted Solution

File Operations on simulator

Hi , I use this for Reading and writing file on Simulator, but it still doesnt work:

 

for writing:

 try
                        {
                                String data = "Data to save on Text file.";
                                FileConnection fc = (FileConnection)
                                Connector.open(System.getProperty("file:///SDCard/"+"test.txt"),Connector.READ_WRITE);  // do i need ///SDCard ??

// I tried also to include test.txt on my project files doesnt work  and i tried also file:///test.txt
                                if(!fc.exists())
                                fc.create();
                                OutputStream os =fc.openOutputStream();
                                byte[] theByteArray = data.getBytes();
                                os.write(theByteArray);
                                os.close();
                                fc.close();
                       
                        }
                    catch (Exception ioe)
                        {
                            Dialog.alert(""+ioe);
                        }

 

I got an Exception : java.lang.IllwgalArgumentException: Null URL

 

 

thanks Guys

Developer
Developer
Posts: 321
Registered: ‎05-26-2009
My Device: Not Specified

Re: File Operations on simulator

My guess is System.getProperty is returning null.

 

 You need to know the full file name including path to open it.

Developer
Posts: 19,633
Registered: ‎07-14-2008
My Device: Not Specified

Re: File Operations on simulator

The use of System.getProperty seems a bit weird to me. 

 

Have you reviewed the FileExplorer demo that comes with the JDE for sample code?

Developer
Posts: 166
Registered: ‎05-07-2009
My Device: Not Specified

Re: File Operations on simulator

I agree with peter_strange, why do you use System.getProperty here? There is definitely no system property called "file:///SDCard/test.txt" so null is expected return value. And null is definitely not valid URL to open.

If you want to access some specific file with given path on the SD card, you might want to use System.getProperty to get URL of SD Card root in proper way with something like System.getProperty("fileconn.dir.memorycard") instead of hardcoding "file:///SDCard/" and then add your relative path (i.e. "test.txt") to the root and pass it to Connector.open


--------------------------------------------------------------------------------------------------------
If your issue is solved, set "Solution" mark at the relevant post.
Don't hesitate to Kudos people whose posts helped you.
Developer
Posts: 54
Registered: ‎05-28-2009
My Device: Not Specified

Re: File Operations on simulator

now  I am using this:   Connector.open("file:///C:/test.txt",Connector.READ_WRITE);

 

at a result:

 

net.rim.device.api.io.file.FileIOException: File system error.

 

 

Developer
Posts: 1,477
Registered: ‎12-30-2008
My Device: Torch 9810

Re: File Operations on simulator

Also the C:\ is not present in the device.. A valid URL will start like file:///SDCard/ or file:///store/ ..

 

By the way, Are you trying to get that text file from your computer's HDD, if yes, it is not the right way and you will never get the file.. You have to simulate a SDCard and add the text file to a desired place within the scope of the SDCard and an absolute path is needed.. I would suggest you to use a predefined System.getProperty..

 

http://www.blackberry.com/knowledgecenterpublic/livelink.exe/fetch/2000/348583/800332/800620/What_Is... 

 

Cheers.. 

--
Manimaran Selvan
Co-Founder, Tech Lead,
Equity Markets Research Group
Highlighted
Developer
Posts: 412
Registered: ‎09-12-2008
My Device: 9000 9810

Re: File Operations on simulator

As other posts tried to explain, you are close to a solution, just need to understand a few more things.

 

1) The files on the SDcard can be accessed by using:

FileConnection fc = (FileConnection) Connector.open("file:///SDCard/test.txt",

Connector.READ_WRITE);

(although you could have asked the system for the SDCard root like this: System.getProperty("fileconn.dir.memorycar"); - but skip this until you know how it works a bit better)

 

2) You want to access the file in simulator (from your app) and the Windows file explorer at the same time?

   Open your JDE and go to Edit->preferences->simulator tab. 

   Now check the 'use PC filesystem for SD Card files' checkbox and browse for the path in the field just below it. 

   The folder you choose will actualy represent the "file:///SDCard/" path in your application.

   Clean way to do things would be to then create a subfolder (with your app name ?) so you don't write in the root (it's just nicer that way)

      - rememeber to change the path in your app in that case (to   "file:///SDCard/<subfolder>/test.txt")

 

 

 After completing 1 and 2 you will have access to the file from within your app as well as from any file browser you use in Windows.

 

 



"Listen carefully, I shall say this only once"
Developer
Posts: 54
Registered: ‎05-28-2009
My Device: Not Specified

Re: File Operations on simulator

yeah that's what I would like to do, use my system files in my simulator, sorry that I didnt ask the question correctly.

 

I tried this:

Open your JDE and go to Edit->preferences->simulator tab.

then choosing memory tab, the check box is readonly , i cant check it,

 

actually all the textboxes, buttons,checkboxes of simulator tab are readonly!!!

 

what do u suggest?

 

thanks Guys

 

Developer
Posts: 54
Registered: ‎05-28-2009
My Device: Not Specified

Re: File Operations on simulator

I change the simulator to 9500 , and it works now,

thanks