boo-urns
boo-urns

Reputation: 10376

IllegalArgumentException: file contains path separator

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.

Upvotes: 6

Views: 15919

Answers (1)

Gabe Sechan
Gabe Sechan

Reputation: 93569

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");

Upvotes: 9

Related Questions