Check if a path represents a file or a folder

前端 未结 8 513
伪装坚强ぢ
伪装坚强ぢ 2020-12-07 21:41

I need a valid method to check if a String represents a path for file or a directory. What are valid directory names in Android? As it comes out, folder names c

8条回答
  •  萌比男神i
    2020-12-07 22:11

    Please stick to the nio API to perform these checks

    import java.nio.file.*;
    
    static Boolean isDir(Path path) {
      if (path == null || !Files.exists(path)) return false;
      else return Files.isDirectory(path);
    }
    

提交回复
热议问题