Skip to content

Instantly share code, notes, and snippets.

@amrishodiq
Created September 27, 2011 02:35
Show Gist options
  • Save amrishodiq/1244173 to your computer and use it in GitHub Desktop.
Save amrishodiq/1244173 to your computer and use it in GitHub Desktop.
Blackberry - Save bytes to file
public static synchronized String saveToFile(String basePath, byte[] data)
throws IOException {
try {
if (basePath.startsWith("file://")) {
// do nothing
} else if (!basePath.startsWith("/"))
basePath = "file:///" + basePath;
else if (basePath.startsWith("//"))
basePath = "file:/" + basePath;
else
basePath = "file://" + basePath;
FileConnection fconn = (FileConnection) Connector.open(basePath,
Connector.READ_WRITE);
if (!fconn.exists())
fconn.create();
fconn.setWritable(true);
OutputStream outputStream = fconn.openOutputStream();
outputStream.write(data);
outputStream.close();
fconn.close();
return basePath;
} catch (IOException e) {
throw e;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment