0

i am using this code

public void onClick(DialogInterface dialog, int which) {
                      File dir = new File (Environment.getExternalStorageDirectory() + "/MyApp/MyFolder");
                       if (dir.isDirectory()) 
                       {
                           File file = new File(card.imagePath);
                           file.delete();
                       }          

But it is not deleting file from the card. Any ideas why?

4

2 回答 2

1

Are you sure about file path?

File file = new File(card.imagePath);

if(file.isExists()){
             file.delete();
             System.out.print("File exists and delete");
} else{
             System.out.print("File NOT exists");
}     

ADD Persmissions ::

 <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
于 2012-04-19T12:23:37.280 回答
1
  • 检查文件是否存在
  • 检查文件权限,如果您对文件有写权限。
于 2012-04-19T12:18:10.487 回答