IllegalArgumentException: File contains a path separator Android

拟墨画扇 提交于 2019-11-30 22:28:40

The openFileInput method will not accept path separators.('/')

it accepts only the name of the file which you want to open/access. so change the statement

outputStream = openFileOutput(patternDirectory.getAbsolutePath().toString(), Context.MODE_APPEND);

to

outputStream = new FileOutputStream (new File(patternDirectory.getAbsolutePath().toString()), true); // true will be same as Context.MODE_APPEND

One problem may be the fact that you do: Environment.getExternalStorageDirectory().getAbsolutePath().toString()+"/com.example.pattern1/myfile.txt" You create a directory that has name myfile.txt

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!