检查文件路径是否为空-最佳做法

时间:2019-02-25 10:41:38

标签: java file null

我目前是技术难题。我正在从应用程序中的资源包中获取某些文件的路径。这是一个键值系统。

如果我的“文件路径”键返回空值。我应该在正常过程中检查无效性还是让我的File或FileUtils API处理?

public class FileTest {

        public save() {
              String path = bundle.getValue("path.key");
              // first option (i find it ugly)
              if(path == null) {
                   new Exception();
              }
              // Option 2
              // Should i check nullity from the key or continue 
              // the process and let the APIs handle the null as illegal argument ?
              try {
                Files.createDirectory(path);
              }catch(IllegalArgumentException e) {
                e.printStackTrace();              
              }
         }
}

有什么意见吗?

0 个答案:

没有答案
相关问题