Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to reference a File in raw folder in Android

I just want to create a File object like this

File myImageFile = new File ("image1") ;

but it is giving me exception of FileNotFoundException
How can i reference a file inside my raw Folder

EDIT: Actually i wanted to do something like this

MultipartEntity multipartEntity= new MultipartEntity(HttpMultipartMode.BROWSER_COMPATIBLE); multipartEntity.addPart("uploaded", new FileBody(new File("myimage")));

like image 205
waseemwk Avatar asked Mar 17 '12 18:03

waseemwk


People also ask

Where is the raw folder on Android?

The raw folder is created inside the res folder: main/res/raw.

How do I play a raw video folder?

Create raw folder under res folder. It must be in a supported format (3gp, wmv, mp4 ) and named with lower case, numerics, underscores and dots in its filename likewise:video_file. mp4. VideoView view = (VideoView)findViewById(R.


1 Answers

You can open it as InputStream, I don't know if possible as a file:

int rid = resources.getIdentifier(packageName + ":raw/" + fileName, null, null);  
//get the file as a stream  
InputStrea is = resources.openRawResource(rid);  
like image 119
MByD Avatar answered Sep 28 '22 01:09

MByD