If you’re familiar with the BlackBerry app deployment, you’ll know that there’re 2 primary ways of installation – the OTA and the desktop. The former requires the .cod and .jad files to be present while the latter requires the .alx and .cod files.
Recently, I had to figure out a way to package a file, say, “test.txt” and place that into the filesystem…during installation. I’m not sure if there’s a better way but I learnt that one way was to basically to open an InputStream pointing to the source “test.txt”, use the FileConnection class to create a file “test.txt” within the BlackBerry device and then use the OutputStream to basically write to the filesystem.
Perhaps sample code will make more sense:-
// Open inputstream to source file String fileName = "test.txt"; InputStream inputStream = getClass().getResourceAsStream(fileName); int fileLen = inputStream.available(); byte[] data = new byte[fileLen]; String target = "file:///store/home/whatever/"+fileName; // Creates a file on the BB with the same name as the source file FileConnection saveFile = (FileConnection)Connector.open(target); saveFile.create(); // Opens the outputstream and writes everything from the inputstream to the file on the BB OutputStream outputStream = saveFile.openOutputStream(); outputStream.write(data); outputStream.close();
If the resource file(s) are huge, it would certainly bloat the .cod file.
Somehow I find this quite inefficient…is there a better way to do this?
Related posts:

0 Responses
Stay in touch with the conversation, subscribe to the RSS feed for comments on this post.