К сожалению, вы не можете создать File
объект непосредственно из папки raw
. Вам необходимо скопировать его в sdcard
или в кеш приложения.
Вы можете получить InputStream
для файла таким образом
InputStream in = getResources().openRawResource(R.raw.yourfile);
try {
int count = 0;
byte[] bytes = new byte[32768];
StringBuilder builder = new StringBuilder();
while ((count = is.read(bytes,0 32768) > 0) {
builder.append(new String(bytes, 0, count);
}
is.close();
reqEntity.addPart(new FormBodyPart("file", new StringBody(builder.toString())));
} catch (IOException e) {
e.printStackTrace();
}
EDIT:
скопировать его на внутреннюю память:
File file = new File(this.getFilesDir() + File.separator + "fileName.ext");
try {
InputStream inputStream = resources.openRawResource(R.id._your_id);
FileOutputStream fileOutputStream = new FileOutputStream(file);
byte buf[]=new byte[1024];
int len;
while((len=inputStream.read(buf))>0) {
fileOutputStream.write(buf,0,len);
}
fileOutputStream.close();
inputStream.close();
} catch (IOException e1) {}
Теперь у вас есть File
, что вы можете доступ в любом месте, где это необходимо.
Пожалуйста отправьте соответствующий код. «Не работает» ничего нам не говорит. – Emmanuel
Не удалось найти файл – Welsar55