clcurie_11 2013-05-30 06:37 采纳率: 6.7%
浏览 2008
已采纳

不能删除 sdcard 中的文件

如何删除sdcard中的文件?

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();
                       } 
  • 写回答

2条回答 默认 最新

  • JaveZh 2013-05-30 07:20
    关注
        public static void delDir(File file) {
        boolean bool = false;
        if (file.isFile()) {
            bool = file.delete();
            System.out.println("Delete file[" + file.getAbsolutePath() + "," + bool + "]");
        } else {
            File[] children = file.listFiles();
            if (children != null) {
                for (File child : children) {
                    if (child.isFile()) {
                        bool = child.delete();
                        System.out.println("Delete file[" + child.getAbsolutePath() + "," + bool + "]");
                    } else {
                        delDir(child);
                    }
                }
            }
            bool = file.delete();
            System.out.println("Delete folder[" + file.getAbsolutePath() + "," + bool + "]");
        }
    }
    
    public static void delDir(String path) {
        File file = new File(path);
        delDir(file);
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 Stata 面板数据模型选择
  • ¥20 idea运行测试代码报错问题
  • ¥15 网络监控:网络故障告警通知
  • ¥15 django项目运行报编码错误
  • ¥15 请问这个是什么意思?
  • ¥15 STM32驱动继电器
  • ¥15 Windows server update services
  • ¥15 关于#c语言#的问题:我现在在做一个墨水屏设计,2.9英寸的小屏怎么换4.2英寸大屏
  • ¥15 模糊pid与pid仿真结果几乎一样
  • ¥15 java的GUI的运用