Creating folder in the application directory

☆樱花仙子☆ 提交于 2019-12-04 10:37:39

Use method Context.getDir() instead. You don't need to invoke mkdirs(), because getDir() will do it automatically.

Quote from the documentation:

Retrieve, creating if needed, a new directory in which the application can place its own custom data files. You can use the returned File object to create and access files in this directory. Note that files created through a File object will only be accessible by your own application; you can only set the mode of the entire directory, not of individual files.

Use this by making a use of getDir()

File dir = ctx.getDir("my_sub_dir", Context.MODE_PRIVATE);
            File newfile = new File(topDirFile.getAbsolutePath() + File.separator + "new_file_name");
            newfile.createNewFile();
            BufferedOutputStream fout = new BufferedOutputStream(new FileOutputStream(newfile));
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!