If you are using Internet Explorer, please remove blackberry.com from your compatibility view settings.

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
Administrator
MSohm
Posts: 14,362
Registered: ‎07-09-2008
My Device: BlackBerry Z30, BlackBerry PlayBook
My Carrier: Bell
Accepted Solution

Create a folder in file system


Quote from the previous forum:
rohan

Posts: 12
Registered: Jun, 2008

Create a folder in file system
Posted: Jul 4, 2008 6:06 AM
 
Hello Everyone,

I want to create a folder in the root file system of the blackberry device. Or you can say anywhere in the device file system I want to make a folder through my code. Would it be possible? How should I approach to achieve this?

Thanks,
- Rohan

 


gmay

Posts: 231
Registered: Jun, 2007

Re: Create a folder in file system
Posted: Jul 4, 2008 10:53 AM
 
To create directories please see FileConnection.mkdir()

http://tinyurl.com/63yj23

Gordon
BlackBerry Developer Journal
www.blackberrydeveloperjournal.com

 

rohan

Posts: 12
Registered: Jun, 2008

Re: Create a folder in file system
Posted: Jul 7, 2008 2:12 AM
 
Hi Gordon,

Thanks for the reply and the link. I have gone through it. But I am not getting how to use FileConnection.mkdir()

Can you please let me know the snippet how to use mkdir?

Thanks,
- Rohan

 

rohan
Posts: 12
Registered: Jun, 2008

Re: Create a folder in file system
Posted: Jul 7, 2008 4:00 AM
 
Hi,

After trying for some time, I got it how to use FileConnection.mkdir() in my code.

But I am facing one problem here. When the mkdir() is executed, it's giving me FileIOException: File system error

Below is my code which is trying to create a directory named myDir


try {
FileConnection fc = (FileConnection) Connector.open("file:///store/home/myDir", Connector.READ_WRITE);
if (!fc.exists()) {
fc.mkdir();
}
} catch (Exception e) {
Dialog.alert(e.toString());
}


I even tried to give path as "file:///store/home/myDir/" because I was trying to make a directory. But that also gives the same exception.

Please let me know if I am making any mistake here.

Thanks,
- Rohan

 

rohan

Posts: 12
Registered: Jun, 2008

Re: Create a folder in file system
Posted: Jul 7, 2008 6:10 AM
 
Hi,

I think the problem is... Blackberry doesn't allow a directory to be created in device's /store/ folder. Because I am able to create a directory in /SDCard/ directory.

Is it something like we cannot create a directory in device's root directory?

 

rohan

Posts: 12
Registered: Jun, 2008

Re: Create a folder in file system
Posted: Jul 7, 2008 6:17 AM
 
Hi,

I am sorry for keep on posting here as I am trying various things in my code and come to know more and more. But I am posting as soon as I get some result, so that it may be useful for others who are trying the same thing.

I even tried to create a directory in /store/home/user/ and it's working fine. So, that means, we have to create our directories inside the /store/home/user or /SDCard/ directory.

Please correct me if I am wrong.

Thanks,
- Rohan

 

yog123

Posts: 2
From: mumbai
Registered: Apr, 2007

Re: Create a folder in file system
Posted: Jul 15, 2008 9:49 AM
 
Can anybody explain this in detail...
When i tried to create folder on memory card or on device memory it gives exception as File System Error...
Is it related to any permission or specific settings..??
JDE 4.2.1.16
Simulator 8100..
Thanks in advance....

Please ensure that the BlackBerry Simulator has been configured to support a micro SD card.  This is done in the BlackBerry JDE by clicking on the Edit menu, selecting Preferences, clicking on the Simulator tab, then the Memory tab and filling in the SD Card size and SD Card image parameters.

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

Re: Create a folder in file system

Hi Yog123,

 

If you go through my all the posts in this thread, you'll come to know that I was getting the same exception when I was trying to create a folder. I have also mentioned the problem and the solution for that as quoted below.

 

"I even tried to create a directory in /store/home/user/ and it's working fine. So, that means, we have to create our directories inside the /store/home/user or /SDCard/ directory."

 

Please let us know if you still find any problem.

 

 

 

Thanks,

- Rohan 

Please use plain text.
Developer
yog123
Posts: 51
Registered: ‎07-15-2008
My Device: Not Specified

Re: Create a folder in file system

hii 

thnks for quick reply...

 

I tried to create folder using mkdir() in sdcard but it says i dnt have read/write access to that folder...

 

my coe snippet goes like this....

 

try {
                FileConnection fconn = (FileConnection)Connector.open("file:///SDCard/BlackBerry/pictures/sp",Connector.READ_WRITE);
               
                boolean write= fconn.canWrite();
                boolean read= fconn.canRead();
                if (!fconn.exists())
                    {
                       
                       
                        fconn.mkdir();  // create the folder/file if it doesn't exist
                     }

 

 is this valid code ......?

 write and read always returns me false

 and on mkdir() call code fails and gives me File System error...

 thnks in advance................

 

Please use plain text.
Developer
Doctor
Posts: 73
Registered: ‎07-15-2008
My Device: Not Specified

Re: Create a folder in file system

Hi yog123,

 

The code you've mentioned is valid code, but I guess you're making a very small mistake here.

Whenever you want to create a directory, you should give "/" after the directory name inside Connector.open()

 

Just put "/" after the directory name "sp" in your code as shown below.

 

 

FileConnection fconn = (FileConnection)Connector.open("file:///SDCard/BlackBerry/pictures/sp/",Connector.READ_WRITE);

 

Please let us know if you still find any problem.

 

 

 

Thanks,

- Rohan 

 

Please use plain text.
Developer
yog123
Posts: 51
Registered: ‎07-15-2008
My Device: Not Specified

Re: Create a folder in file system

 

thnks alot......

 

it finally works......

 

 

Please use plain text.
Developer
Doctor
Posts: 73
Registered: ‎07-15-2008
My Device: Not Specified

Re: Create a folder in file system

Cheers!

:smileyhappy:

 

Hi Mark,

I think now you can make this thread as "solved".

 

 

 

Thanks,

- Rohan 

Please use plain text.
New Developer
vilastalewale
Posts: 13
Registered: ‎08-27-2008
My Device: Not Specified

Re: Create a folder in file system

Thanks i am also able to create folder on SD Card

Now i like to know how to write text file in that folder

Please use plain text.
Developer
justindutoit
Posts: 400
Registered: ‎05-31-2009
My Device: Not Specified

Re: Create a folder in file system

(Thought I'd try even thought this thread is ancient:smileyhappy:

Hi- I'd like to make the directory

 

store/Device Memory/home/user/pictures/MDB/

 

on a Storm simulator 9530. I'm doing it one dir at a time. I get an Invalid Op file system error trying to create the Device Memory/ dir, even though it creates store/ just fine.

 

I would have thought store/Device Memory/home/user/ would exist already. How do I do this on the Storm and for Bold 9700 and Storm2 please?

 

Thanks

Justin D.

 

Please use plain text.
Developer
Developer
CMY
Posts: 1,122
Registered: ‎02-10-2009
My Device: 8130 / 8350 / 9530 / 9550 / 9850 / PlayBook
My Carrier: Verizon

Re: Create a folder in file system

Everything up to the MDB should already exist. Make sure you have the card mouhnted in the simulator. You should not be able to access anything below the user folder from a third party app anyhow, if i remember correctly.

Please use plain text.
Developer
justindutoit
Posts: 400
Registered: ‎05-31-2009
My Device: Not Specified

Re: Create a folder in file system

Hey thanks for that. Just tried to create a file

 

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

 

on the Storm 9530 sim and got a FIle System Error- Invalid Operation.

 

Help!

 

J

Please use plain text.