File mkdirs() method not working in android/java

后端 未结 4 1117
不知归路
不知归路 2020-12-19 00:44

I\'ve been pulling out my hair on this for a while now. The following method is supposed to download a file, and save it to the location specified on the hard drive.

<
4条回答
  •  爱一瞬间的悲伤
    2020-12-19 01:05

    Are you sure that mkdirs is failing? Why don't you check the return value of the mkdirs call and log an error message if it returns false?

    if (!file.getParentFile().exists() && !file.getParentFile().mkdirs()){
      log("Unable to create " + file.getParentFile());
    }
    

    I suspect that you might be surprised with what the file was...

    PS - and please do something with that error handler - at minimum, log the error. Catching Exception and doing a silent return is horrible practice.

提交回复
热议问题