java.io.FileNotFoundException, open failed: ENOENT

前端 未结 4 1080
时光取名叫无心
时光取名叫无心 2020-12-21 16:31

For some reason I am getting a fileNotFoundException for both the times I read. Something worth noting is that the Toast prints \"File exists!\". I used the

4条回答
  •  無奈伤痛
    2020-12-21 17:01

    getFilesDir returns a File object. If you call onString on it (which you do implicitly), it returns its path. The path is not ending with a slash if the file is a directory, so getActivity().getFilesDir()+filename will result in something like "/data/data/com.yourapp/filescalendar_recipes.txt".

    You can either use getActivity().getFilesDir()+File.separator+filename, or just call new FileInputStream(file).

提交回复
热议问题