I am usin MultipartEntity and I am trying to refer to the file in the raw folder. Here is the code:
MultipartEntity reqEntity = new MultipartEntity();
reqEntity.addPart(new FormBodyPart("file", new FileBody(new File("test.txt"))));
The test.txt file is in my res/raw folder. When I execute the code I get the following exception : FileNotFoundException: /test.txt: open failed: ENOENT (No such file or directory)
Can anyone help me with this?
Unfortunately you can not create a
File
object directly from the raw folder. You need to copy it or in your sdcard or inside the application`s cache.you can retrieve the InputStream for your file this way
You can put the file in the /res/raw directory, where the file will be indexed and is accessible by an id in the R file: