File.createNewFile() thowing IOException No such file or directory

后端 未结 9 2434
感动是毒
感动是毒 2020-12-15 03:51

I have a method that writes to a log file. If the file exists it should append to it, if not then I want it to create a new file.

if (!file.exists() &&am         


        
相关标签:
9条回答
  • 2020-12-15 04:18

    You are certainly getting this Exception 'The system cannot find the path specified'

    Just print 'file.getAbsoluteFile()' , this will let you know what is the file you wanted to create.

    This exception will occur if the Directory where you are creating the file doesn't exist.

    0 讨论(0)
  • 2020-12-15 04:21

    In my case was just a lack of permission:

    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />

    0 讨论(0)
  • 2020-12-15 04:31

    try to ensure the parent directory exists with:

    file.getParentFile().mkdirs()
    
    0 讨论(0)
提交回复
热议问题