06-24-2011 04:49 AM
Hi,
I'm developing my first WebWorks project using the Eclipse plug-in and I'm getting the following error when I try to access a file in device memory (using the simulator):
javax.microedition.io.ConnectionNotFoundException: Protocol not found: net.rim.device.cldc.io.local.Protocol
I came across the following code that shows how to access a file on the SD card so I imported the code into Eclipse and it works fine:
However, when I change the sample code to use device memory instead of the SD card it also encounters the same problem. The original code was:
var filePath = "file:///SDCard/myDataFile.txt";
var backupPath = "file:///SDCard/myDataFile2.txt";
I changed it to:
var filePath = "local:///myDataFile.txt";
var backupPath = "local:///myDataFile2.txt";
I've spent ages googling this problem but, so far, haven't managed to track down an answer. Any help would be much appreciated. Apologies in advance if I'm doing something stupid!
Thanks.
06-26-2011 05:50 AM
var filePath;
function
setFilePath() {
var root = blackberry.io.dir.getRootDirs();
filePath = root +'/MyFile.txt';
}
remember to add feature in cofig.xml.
blackberry.io.dir
blakberry.io.file
works for me
06-26-2011 07:49 AM
The local:// protocol is for accessing files inside your application archive using AJAX or by linking to it in an anchor tag, image tag etc.
An example of accessing the in memory file system is:
file:///store/home/user/pictures/
06-28-2011 10:18 AM
Thanks Tim, I've got it working now. I added some code to, first of all, create my own directory in file:///store/home/user and now it's working fine.
Do BB Apps normally ask the user where they would like to store their data the first time the App is run? If not, should the default location be device memory or SD card? For example, I was thinking of storing the data in either of the following locations:
1) file:///store/home/user/MyCompanyName/MyProductName/subfolders...
2) file:///SDCard/MyCompanyName/MyProductName/subfolders...
Would that be following "good practice" in the BB App world?
Should I give the user the option of changing the location at a later date and automatically moving all of the existing folders / files for them?
Thanks again for your help.
06-28-2011 10:22 AM
If it is small amounts of data you could likely get away with just storing it in the memory file system.. If you are going to be storing large amounts of data, or data that you would want to be removable then the SDCard is a definate option.
I don't think it would hurt to ask them where they would like to store their app data.