audio - Accessing Files in the Raw folder in Android -
i working on exporting function in android application. files wav files stored in res/raw folder. how can access files?
uri = uri.parse("android.resource://" + getpackagename() + "/raw/" + selection[i]); try{ file[i] = new file(uri.getpath()); if(file[i].exists()){ log.i("exist", "exist"); }else{ log.i("exist", "not"); } } catch(exception e){ log.i("error", "file not found"); }
selection[i] filename of file need in res/raw folder. code returns "not", means has not found file want res/raw folder. can me please? thanks.
i'm not sure can access resource through file
that. here's how i'm reading html files in raw folder:
public static string getstringfromresource(context context, @rawres int id) { bufferedreader reader = null; try { stringbuilder stringbuilder = new stringbuilder(); inputstream inputstream = context.getresources().openrawresource(id); reader = new bufferedreader(new inputstreamreader(inputstream)); string currentline; while ((currentline = reader.readline()) != null ) { stringbuilder.append(currentline); } return stringbuilder.tostring(); } catch (ioexception e) { log.e(tag, "error opening raw resource: " + id); } { if (reader != null) { try { reader.close(); } catch (ioexception e) { log.e(tag, "error closing raw resource: " + id, e); } } } return null; }
the key part inputstream inputstream = context.getresources().openrawresource(id);
call gets stream file. use stream write output file exporting.
Comments
Post a Comment