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: 73
Registered: ‎07-15-2008
My Device: Not Specified

Re: Create a folder in file system

Can you please give us the code and the exact error/exception you are getting?

 

- Rohan

Developer
Posts: 489
Registered: ‎05-31-2009
My Device: Not Specified

Re: Create a folder in file system

Hey. I got a FileIOException, error code 12 which is Invalid Operation and exc.getMessage is File System Error. The code is below. An example of the filename to create on the Storm 9530 simulator is

 

store/Device Memory/home/user/pictures/MDBcurrentBackgroundPlus0.jpg

 

Tks

 

J.

 

        
        OutputStream out = null;
        FileConnection filecon = null;
        String exceptionText = null;
        
        String path = GetPathToBackgrounds();

        try {
            
            filecon = (FileConnection) Connector.open(path + "MDBcurrentBackgroundPlus" + number + ".jpg", Connector.READ_WRITE);    
            
            if (!filecon.exists())
                    filecon.create();   // <<< Exception here
                    
             out = filecon.openOutputStream();
             out.write(bitmapBytes);
             out.close();
        }
        catch (net.rim.device.api.io.file.FileIOException e) {
         
            int code = e.getErrorCode();  // 12 on Storm 9530
            String msg = e.getMessage();  // File System Error

 

Developer
Developer
Posts: 1,123
Registered: ‎02-10-2009
My Device: 8130 / 8350 / 9530 / 9550 / 9850 / PlayBook
My Carrier: Verizon

Re: Create a folder in file system

[ Edited ]

What does pathToBackgrounds return?  Remeber that to open a file it needs to be prefixed with the file protocol handler file:///.

Developer
Posts: 489
Registered: ‎05-31-2009
My Device: Not Specified

Re: Create a folder in file system

Yes it's the same as the path I mentioned (store/ etc) and the file:/// is there.

 

Cheers,

J

Developer
Posts: 73
Registered: ‎07-15-2008
My Device: Not Specified

Re: Create a folder in file system

Have you tried hardcoding the path instead of getting from GetPathToBackgrounds() method? Just to check, hardcode the entire file name including path and check if file is being created or not.

Contributor
Posts: 24
Registered: ‎07-24-2009
My Device: Not Specified

Re: Create a folder in file system

Good god! That frickin "/" at the end of the directory name is what I missed too. Thank you so much Doctor.

Contributor
Posts: 17
Registered: ‎03-03-2011
My Device: 9800

Re: Create a folder in file system

Hello

I want to know how to create sub folder in a file system. Means the coding which u guys provided can make only one folder. I want to make sub folders. I am using eclipse plugin for blackberry. Waiting for your reply.

Thanks

 

New Contributor
Posts: 8
Registered: ‎09-26-2012
My Device: BB 9300
My Carrier: Rogers

Re: Create a folder in file system

I am quite lost here.  My situation is as follows....I have installed an app in my BB phone, and it reads files the user creates on his/her PC.  Mail the file to yourself, and download it.  The problem is he is not given a choice as to where that file goes when downloaded.....it seems to go into the root of the SD card.  OK, the app has a button to tell it where the file(s) are located, except it cannot access the root.  I can't find how to create a folder under the root, nor can I find a way to move the downloaded file to the new folder, even if I had been able to create one.  It seems the only way around this is to hook the BB up to a PC, and use Windows Explorer to straighten everything out.  I regret to say I am not impressed.

Developer
Posts: 16,637
Registered: ‎07-29-2008
My Device: Z10 LE, Z30, Passport
My Carrier: O2 Germany

Re: Create a folder in file system

please open a new thread for your issue.
you can link relevant threads.
----------------------------------------------------------
feel free to press the like button on the right side to thank the user that helped you.
please mark posts as solved if you found a solution.
@SimonHain on twitter
Developer
Posts: 209
Registered: ‎04-30-2011
My Device: BlackBerry Z10
My Carrier: Airtel

Re: Create a folder in file system

HI maryemsiddiqui

 

	try {
			FileConnection fc = (FileConnection) Connector.open("file:///store/home/pawan/", Connector.READ_WRITE);
			
			//pawan is first folder name
			if (!fc.exists()) {
				fc.mkdir();
				//jha is sub folder name under the pawan folder.				
				fc = (FileConnection) Connector.open("file:///store/home/pawan/jha/", Connector.READ_WRITE);	
				if (!fc.exists()) {
					fc.mkdir();
					if(fc.exists())
						Dialog.alert("done");	
					}
				}
			} catch (Exception e) {
				Dialog.alert(e.toString());
			} 

 

 

 

Thanks

Pawan