Question

I'm struggling with this for about 2 hours now. I'm just trying to read an image that is inside the folder on my desktop. Was trying many different ways but nothing works.

String path = "C:\\Users\\User1\\Desktop\\My logos\\";
String _image = "walcott.png";
File imgFile = new File(path+_image);
if(imgFile.exists())
{
 Log.d("OMG FILE EXIST!", imgFile.getAbsolutePath());
    }

Any ideas? Aww and the image is png.

Thanks!

Était-ce utile?

La solution

Impossible, first off the code is running on an Android device so it's gonna search for a C:/ disk on de device.

It is possible to get files from outside the app package by checking the sd card for particular files, but still an sd card on the device of course.

As example:

File sdCardLocation = new File(
    Environment.getExternalStorageDirectory(),
    "//FolderOrFile//OnTheSDCard.png"
);

if(sdCardLocation.exists())
    Log.d("OMG SDCARD EXIST!", sdCardLocation.getAbsolutePath());

But you have to add this permission to your AndroidManifest.xml:

<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top