The key to storing a file in your COD for deployment to the BlackBerry file system: store it in the src folder. Then use the basic input and output streams for reading and writing.
/**
* Write out a file stored in the COD.
* @param filename - filename must start with /
* @param location - example: file:///store/home/user
* @throws Exception
*/
private void writeFile(String filename, String location) throws Exception
{
InputStream inputStream = null;
inputStream = getClass().getResourceAsStream(filename);
if(inputStream == null)
throw new Exception("Unable to open input file: " + filename);
FileConnection fc = (FileConnection)Connector.open(location + filename);
if (!fc.exists()) {
fc.create();
}
OutputStream outStream = fc.openOutputStream();
outStream.write(IOUtilities.streamToBytes(inputStream));
outStream.close();
fc.close();
}
Advertisement