【问题标题】:(android)How to write code to check a file in a folder(android)如何编写代码来检查文件夹中的文件
【发布时间】:2015-07-19 09:29:30
【问题描述】:

我在“/Android/data/Myfolder”中有一个music.mp3文件,我想编写代码来检查Myfolder中是否有music.mp3文件。现在,我不知道如何编写代码那个。

【问题讨论】:

  • stackoverflow 不是代码编写服务,请先帮助自己,谷歌是你的朋友,我们你在任何阶段都卡住了,问,你会得到所有的帮助。
  • "/Android/data/Myfolder"。该文件夹 /Android/data 不存在。不在单个设备上。请先找出真正的路径。无论如何,您必须使用完整路径。

标签: java android file android-file


【解决方案1】:

尝试像这样使用Fileexists() 方法:-

  String folderPath = "/Android/data/Myfolder";
        String fileName = "music.mp3";
        File music = new File(folderPath+"/"+fileName);
        if(music.exists()){ // return true if found
            System.out.println(fileName +"found");
            // other found logics here
        }

        else {
            System.out.println(fileName +" not found here");
            // other not found logics here
        }

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2020-12-21
    • 1970-01-01
    • 2015-10-22
    • 2020-07-15
    • 2021-11-27
    • 2011-08-28
    • 2013-05-22
    相关资源
    最近更新 更多