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 Developer
riddhi
Posts: 10
Registered: ‎12-24-2009
My Device: 9500

Location of File Creation in Blackberry/Code

Hi,

     I would like to create file in Blackberry Simulator to store information. Could you please tell me if the same code for creation of Java file will do or we have different code. Please provide them.

 

  Also, tell me the Location where the file will be stored.

 

Thanks,

Riddhi

Please use plain text.
Developer
rcmaniac25
Posts: 1,805
Registered: ‎04-28-2009
My Device: Z10 (STL100-4)-10.2.1.3253, Z10 (STL100-3)-10.3.1.634 Dev OS, Z30 (STA100-5)-10.3.1.634 Dev OS, Passport (SQW100-1)-10.3.0.1418, PlayBook (16GB)-2.1.0.1917

Re: Location of File Creation in Blackberry/Code

I'm not exactly sure what you mean by your second sentence. The general process of creating a file is:

FileConnection file = (FileConnection)Connector.open("path");
if(!file.exists())
{
	//If the file doesn't exist then create it.
	file.create();
}
//CODE HERE
file.close();

 Where "path" is you would have file:///{root}/{path}/{file_name}. Root is SDCard (self explanatory)/store (the BlackBerry's flash memory). Path is whatever path you want the file to have, file_name is the file name. Pretty simple.

 

The hard part is that files must be created in a folder that already exists, if the folder does not exist then it must be created (same code as above but instead of create you use mkdir). It must created hierarchical from the top down, so if you need a folder structure like this/is/a/folder and you need to create "folder" and the only currently existing folder is "this" then you need to create "is" followed by "a" followed by "folder." You can't just create "folder", it wil throw an exception.

 

All this information is avalible in the FileConnection documentation (for paths you should look at the getName, getPath, getURL functions in FileConnection).

---Spends time in #blackberrydev on freenode (IRC)----
Three simple rules:
1. Please use the search bar before making new posts.
2. "Like" posts that you find helpful.
3. If a solution has been found for your post, mark it as solved.
--I code too much. Well, too bad.
Please use plain text.
New Developer
riddhi
Posts: 10
Registered: ‎12-24-2009
My Device: 9500

Re: Location of File Creation in Blackberry/Code

Thanks alot for the input. Please tell me how to find the "Download" folder for Simulator 9350. Can we creat folder in it?

 

Please use plain text.
Developer
rcmaniac25
Posts: 1,805
Registered: ‎04-28-2009
My Device: Z10 (STL100-4)-10.2.1.3253, Z10 (STL100-3)-10.3.1.634 Dev OS, Z30 (STA100-5)-10.3.1.634 Dev OS, Passport (SQW100-1)-10.3.0.1418, PlayBook (16GB)-2.1.0.1917

Re: Location of File Creation in Blackberry/Code

The "Download" folder is on your homescreen. When you install a new app it will automatically go there. This only happens on OS 4.7 and above and with 5.0 you can specify which folder the app goes to.

---Spends time in #blackberrydev on freenode (IRC)----
Three simple rules:
1. Please use the search bar before making new posts.
2. "Like" posts that you find helpful.
3. If a solution has been found for your post, mark it as solved.
--I code too much. Well, too bad.
Please use plain text.
New Developer
riddhi
Posts: 10
Registered: ‎12-24-2009
My Device: 9500

Re: Location of File Creation in Blackberry/Code

 I want to specify the application to create folder in the Download folder and to store file in it. could you please suggest how to go about it?

 

Thanks,

Riddhiman.

Please use plain text.
Developer
rcmaniac25
Posts: 1,805
Registered: ‎04-28-2009
My Device: Z10 (STL100-4)-10.2.1.3253, Z10 (STL100-3)-10.3.1.634 Dev OS, Z30 (STA100-5)-10.3.1.634 Dev OS, Passport (SQW100-1)-10.3.0.1418, PlayBook (16GB)-2.1.0.1917

Re: Location of File Creation in Blackberry/Code

I don't know how to do that, you should create another post for that question. As for a anwser to your PM about appending data:

To append to a file simply call openOutputStream(long byteOffset) and pass a number that is greater then the size of the file (size can be retrieved using fileSize()) because it will place the file pointer right at the end of the file. Write the data to the OutputStream and it will be appended.

---Spends time in #blackberrydev on freenode (IRC)----
Three simple rules:
1. Please use the search bar before making new posts.
2. "Like" posts that you find helpful.
3. If a solution has been found for your post, mark it as solved.
--I code too much. Well, too bad.
Please use plain text.
New Developer
kavita_kt1
Posts: 2
Registered: ‎01-28-2010
My Device: blackberry

Re: Location of File Creation in Blackberry/Code

How to create file in blackberry application

My code is

try
                {
                                        FileConnection fconn = (FileConnection)Connector.open("file:///E:/testfile.txt", Connector.READ_WRITE);                    
                                        if (!fconn.exists())
                    {
                                                fconn.create();
                    } 
                                   catch(Exception ex)
                {
                                     }

This code canot be create a file

Please use plain text.