user2173859
user2173859

Reputation: 57

Eclipse (simulator Android tablet) File Not Found even though file exists

I am trying to read a file. I do not mind the location, so I have tried various locations and ways to do this:

File file = new File("DFirstPdf.pdf");
File file = new File("C:/DFirstPdf.pdf");
File file = new File("C:\\DFirstPdf.pdf");

But I always get that file does not exist. I am working whit Eclipse and a simulator and I do not have more ideas.

What I want to do is: if (file.exists()) { Uri path = Uri.fromFile(file); Intent intent = new Intent(Intent.ACTION_VIEW); intent.setDataAndType(path, "application/pdf"); intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);

PackageManager pm = getPackageManager();

List<ResolveInfo> activities = pm.queryIntentActivities(intent, 0);

if (activities.size() > 0) 
{
startActivity(intent);
}
else
{
// Do something else here. Maybe pop up a Dialog or Toast
}

Upvotes: 0

Views: 272

Answers (2)

Jirawat Uttayaya
Jirawat Uttayaya

Reputation: 1312

You have to use the classloader to get the resource

PackageManager.class.getClassLoader().getResource("DFirstPdf.pdf");

Upvotes: 1

Gabe Sechan
Gabe Sechan

Reputation: 93678

THe simulator has its own filesystem. It won't see files on your machine. ANd it has a UNIX style path, not a windows style one.

Upvotes: 0

Related Questions