0
我寫了一些代碼,可以讓我在Android內部存儲器的數據/數據中保存圖片。現在我想知道是否有辦法從內部存儲器中刪除這些圖片。如何在Android中以編程方式刪除圖片?
以下是我對儲蓄:
public boolean saveImg(String showId) {
try {
URL url = new URL(getImgUrl(showId));
File file = new File(showId + ".jpg");
/* Open a connection to that URL. */
URLConnection ucon = url.openConnection();
//Define InputStreams to read from the URLConnection.
InputStream is = ucon.getInputStream();
BufferedInputStream bis = new BufferedInputStream(is);
//Read bytes to the Buffer until there is nothing more to read(-1).
ByteArrayBuffer baf = new ByteArrayBuffer(50);
int current = 0;
while ((current = bis.read()) != -1) {
baf.append((byte) current);
}
//Convert the Bytes read to a String.
FileOutputStream fos = new FileOutputStream(PATH+file);
fos.write(baf.toByteArray());
fos.close();
return true;
} catch (IOException e) {
return false;
}
}
我試過,但它不會從數據/數據刪除。任何關於我在做什麼的錯誤?
public void DeleteImg(String showId) {
File file = new File(PATH + showId +".jpg");
file.delete();
}
嗯,我試過了。模擬器運行時不會崩潰。該節目從我的列表視圖中刪除,但當看看數據/數據時,我仍然看到文件::: public void DeleteImg(String showId){ File file = new File(PATH + showId +「。jpg」); file.delete(); } – user661135 2011-03-29 18:51:37