我有一种方法可以从 url 下载图像并将其保存在内部存储的文件夹中
public void saveDynamicImage(String url,String fileName, String folderName) {
InputStream iStream;
BufferedInputStream buffInputStream;
ByteArrayBuffer byteArray = null;
try {
HttpGet httpGet = new HttpGet(url);
HttpClient httpClient = new DefaultHttpClient();
HttpResponse httpResponse = httpClient.execute(httpGet);
iStream = httpResponse.getEntity().getContent();
buffInputStream = new BufferedInputStream(iStream, 8 * 1024);
byteArray = new ByteArrayBuffer(50);
int current = 0;
while ((current = buffInputStream.read()) != -1) {
byteArray.append((byte) current);
}
} catch (ClientProtocolException e1) {
} catch (IOException e1) {
}
File dynamicImageDir = context.getDir(AppConstants.DYNAMIC_IMAGE, Context.MODE_PRIVATE);
File appNamefileDir = new File(dynamicImageDir, BaseActivity.appDataStore.getAppName());
appNamefileDir.mkdirs();
File controlNameDir = new File(appNamefileDir, folderName);
controlNameDir.mkdirs();
File file = new File(controlNameDir, fileName);
try {
FileOutputStream outputStream = new FileOutputStream(file);
outputStream.write(byteArray.toByteArray());
outputStream.close();
System.out.println("DynamicImage saving over!..");
} catch (FileNotFoundException e) {
} catch (IOException e) {
}
}
我想在某个时间点删除整个目录。我删除整个目录的方法是
public void deleteDynamicImage() throws NullPointerException,FileNotFoundException {
File rootDirectory = context.getDir(AppConstants.DYNAMIC_IMAGE, Context.MODE_WORLD_WRITEABLE);
boolean status = rootDirectory.delete();
Log.e("", "delete : "+status);
}
我的状态为“假”。文件已创建并且工作正常。唯一的问题是删除。有什么我想念的吗?