Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

IllegalArgumentException: file contains path separator

Tags:

android

I'm trying to check whether a zip exists in a subdirectory in the application's internal storage:

File file = this.getApplicationContext().getFileStreamPath(this.getFilesDir().getAbsolutePath() + "/thesubdirectory/the.zip";
if(file.exists()) {
    Log.e(this.class.getName(), "file exists");
}

This is throwing a java.lang.IllegalArgumentException: File /data/data/my.package.name/files/thesubdirectory/the.zip contains a path separator.

Why is this happening? I thought this was the way you should check whether a file exists.

like image 305
user5243421 Avatar asked Jan 20 '13 05:01

user5243421


1 Answers

file.exists is. But getFileStreamPath can't take a path, it needs to take a filename in that directory. Try this:

File file = new File(this.getFilesDir().getAbsolutePath() + "/thesubdirectory/the.zip");
like image 98
Gabe Sechan Avatar answered Sep 18 '22 12:09

Gabe Sechan