Created
September 27, 2011 07:29
-
-
Save amrishodiq/1244535 to your computer and use it in GitHub Desktop.
Blackberry - Delete a file
This file contains hidden or 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 void deleteFile(String path) { | |
if (path.startsWith("file://")) { | |
// do nothing | |
} else if (!path.startsWith("/")) | |
path = "file:///" + path; | |
else if (path.startsWith("//")) | |
path = "file:/" + path; | |
else | |
path = "file://" + path; | |
try { | |
FileConnection file = (FileConnection) Connector.open(path, | |
Connector.READ_WRITE); | |
if (file.exists()) { | |
file.setWritable(true); | |
file.delete(); | |
} | |
file.close(); | |
} catch (IOException ex) { | |
System.out.println("File cannot be deleted"); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment