12-30-2009 08:57 AM
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
12-30-2009 09:55 AM
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).
12-31-2009 06:07 AM
Thanks alot for the input. Please tell me how to find the "Download" folder for Simulator 9350. Can we creat folder in it?
12-31-2009 10:15 AM
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.
01-01-2010 01:52 AM
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.
01-01-2010 02:41 AM
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.
02-11-2010 04:04 AM
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