Created
September 27, 2011 02:35
-
-
Save amrishodiq/1244173 to your computer and use it in GitHub Desktop.
Blackberry - Save bytes to file
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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