openRawResourceFd fails on android
up vote
5
down vote
favorite
I'm writing my first Android application, and I'm trying to read a res/raw resource file.
The following code throws a FileNotFound Exception:
AssetFileDescriptor fd = res.openRawResourceFd(R.raw.myfile);
but this line of code works:
InputStream stream = res.openRawResource (R.raw.myfile);
I need the AssetFileDescriptor in order to determine the length of the file. Any ideas why it isn't working?
add a comment |
up vote
5
down vote
favorite
I'm writing my first Android application, and I'm trying to read a res/raw resource file.
The following code throws a FileNotFound Exception:
AssetFileDescriptor fd = res.openRawResourceFd(R.raw.myfile);
but this line of code works:
InputStream stream = res.openRawResource (R.raw.myfile);
I need the AssetFileDescriptor in order to determine the length of the file. Any ideas why it isn't working?
did you find any way to do this??
– shridutt kothari
Jun 9 '15 at 16:02
add a comment |
up vote
5
down vote
favorite
up vote
5
down vote
favorite
I'm writing my first Android application, and I'm trying to read a res/raw resource file.
The following code throws a FileNotFound Exception:
AssetFileDescriptor fd = res.openRawResourceFd(R.raw.myfile);
but this line of code works:
InputStream stream = res.openRawResource (R.raw.myfile);
I need the AssetFileDescriptor in order to determine the length of the file. Any ideas why it isn't working?
I'm writing my first Android application, and I'm trying to read a res/raw resource file.
The following code throws a FileNotFound Exception:
AssetFileDescriptor fd = res.openRawResourceFd(R.raw.myfile);
but this line of code works:
InputStream stream = res.openRawResource (R.raw.myfile);
I need the AssetFileDescriptor in order to determine the length of the file. Any ideas why it isn't working?
edited Nov 22 '11 at 5:29
Vivek Kalkur
1,65521739
1,65521739
asked Nov 22 '11 at 4:54
WOPR
1422512
1422512
did you find any way to do this??
– shridutt kothari
Jun 9 '15 at 16:02
add a comment |
did you find any way to do this??
– shridutt kothari
Jun 9 '15 at 16:02
did you find any way to do this??
– shridutt kothari
Jun 9 '15 at 16:02
did you find any way to do this??
– shridutt kothari
Jun 9 '15 at 16:02
add a comment |
3 Answers
3
active
oldest
votes
up vote
5
down vote
You can do it this way:
FileDescriptor fd = getResources().openRawResourceFd(R.raw.rawResourceId).getFileDescriptor();
No try/catch block required.
add a comment |
up vote
1
down vote
This works;
AssetFileDescriptor afd = res.openRawResourceFd(R.raw.rawResourceId);
add a comment |
up vote
0
down vote
Move your myfile to asset folder and try this
try
AssetFileDescriptor descriptor = getAssets().openFd( "myfile" );
FileDescriptor fd = descriptor.getFileDescriptor();
catch(Exception)
Or you can try to open a RAW file from the resources/raw foder with this code:
FileDescriptor fd = getResources().openRawResourceFd(R.raw.myfile).getFileDescriptor();
1
This is not the permanent solution, as in asset folder i am getting file is compressed error for which i need to put file in raw directory only see this thread stackoverflow.com/questions/6186866/…
– shridutt kothari
Jun 9 '15 at 16:03
openRawResource returns Inputstream and not FileInputStream
– ozmank
Feb 11 '16 at 8:42
add a comment |
3 Answers
3
active
oldest
votes
3 Answers
3
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
5
down vote
You can do it this way:
FileDescriptor fd = getResources().openRawResourceFd(R.raw.rawResourceId).getFileDescriptor();
No try/catch block required.
add a comment |
up vote
5
down vote
You can do it this way:
FileDescriptor fd = getResources().openRawResourceFd(R.raw.rawResourceId).getFileDescriptor();
No try/catch block required.
add a comment |
up vote
5
down vote
up vote
5
down vote
You can do it this way:
FileDescriptor fd = getResources().openRawResourceFd(R.raw.rawResourceId).getFileDescriptor();
No try/catch block required.
You can do it this way:
FileDescriptor fd = getResources().openRawResourceFd(R.raw.rawResourceId).getFileDescriptor();
No try/catch block required.
answered Jan 22 '14 at 16:03
Chepech
3,52133460
3,52133460
add a comment |
add a comment |
up vote
1
down vote
This works;
AssetFileDescriptor afd = res.openRawResourceFd(R.raw.rawResourceId);
add a comment |
up vote
1
down vote
This works;
AssetFileDescriptor afd = res.openRawResourceFd(R.raw.rawResourceId);
add a comment |
up vote
1
down vote
up vote
1
down vote
This works;
AssetFileDescriptor afd = res.openRawResourceFd(R.raw.rawResourceId);
This works;
AssetFileDescriptor afd = res.openRawResourceFd(R.raw.rawResourceId);
answered Nov 8 '15 at 23:43
Jessicardo
6181612
6181612
add a comment |
add a comment |
up vote
0
down vote
Move your myfile to asset folder and try this
try
AssetFileDescriptor descriptor = getAssets().openFd( "myfile" );
FileDescriptor fd = descriptor.getFileDescriptor();
catch(Exception)
Or you can try to open a RAW file from the resources/raw foder with this code:
FileDescriptor fd = getResources().openRawResourceFd(R.raw.myfile).getFileDescriptor();
1
This is not the permanent solution, as in asset folder i am getting file is compressed error for which i need to put file in raw directory only see this thread stackoverflow.com/questions/6186866/…
– shridutt kothari
Jun 9 '15 at 16:03
openRawResource returns Inputstream and not FileInputStream
– ozmank
Feb 11 '16 at 8:42
add a comment |
up vote
0
down vote
Move your myfile to asset folder and try this
try
AssetFileDescriptor descriptor = getAssets().openFd( "myfile" );
FileDescriptor fd = descriptor.getFileDescriptor();
catch(Exception)
Or you can try to open a RAW file from the resources/raw foder with this code:
FileDescriptor fd = getResources().openRawResourceFd(R.raw.myfile).getFileDescriptor();
1
This is not the permanent solution, as in asset folder i am getting file is compressed error for which i need to put file in raw directory only see this thread stackoverflow.com/questions/6186866/…
– shridutt kothari
Jun 9 '15 at 16:03
openRawResource returns Inputstream and not FileInputStream
– ozmank
Feb 11 '16 at 8:42
add a comment |
up vote
0
down vote
up vote
0
down vote
Move your myfile to asset folder and try this
try
AssetFileDescriptor descriptor = getAssets().openFd( "myfile" );
FileDescriptor fd = descriptor.getFileDescriptor();
catch(Exception)
Or you can try to open a RAW file from the resources/raw foder with this code:
FileDescriptor fd = getResources().openRawResourceFd(R.raw.myfile).getFileDescriptor();
Move your myfile to asset folder and try this
try
AssetFileDescriptor descriptor = getAssets().openFd( "myfile" );
FileDescriptor fd = descriptor.getFileDescriptor();
catch(Exception)
Or you can try to open a RAW file from the resources/raw foder with this code:
FileDescriptor fd = getResources().openRawResourceFd(R.raw.myfile).getFileDescriptor();
edited Nov 10 at 12:51
Carlos Alberto Martínez Gadea
1,09311224
1,09311224
answered Nov 22 '11 at 5:32
Pawan
1,06021725
1,06021725
1
This is not the permanent solution, as in asset folder i am getting file is compressed error for which i need to put file in raw directory only see this thread stackoverflow.com/questions/6186866/…
– shridutt kothari
Jun 9 '15 at 16:03
openRawResource returns Inputstream and not FileInputStream
– ozmank
Feb 11 '16 at 8:42
add a comment |
1
This is not the permanent solution, as in asset folder i am getting file is compressed error for which i need to put file in raw directory only see this thread stackoverflow.com/questions/6186866/…
– shridutt kothari
Jun 9 '15 at 16:03
openRawResource returns Inputstream and not FileInputStream
– ozmank
Feb 11 '16 at 8:42
1
1
This is not the permanent solution, as in asset folder i am getting file is compressed error for which i need to put file in raw directory only see this thread stackoverflow.com/questions/6186866/…
– shridutt kothari
Jun 9 '15 at 16:03
This is not the permanent solution, as in asset folder i am getting file is compressed error for which i need to put file in raw directory only see this thread stackoverflow.com/questions/6186866/…
– shridutt kothari
Jun 9 '15 at 16:03
openRawResource returns Inputstream and not FileInputStream
– ozmank
Feb 11 '16 at 8:42
openRawResource returns Inputstream and not FileInputStream
– ozmank
Feb 11 '16 at 8:42
add a comment |
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f8222162%2fopenrawresourcefd-fails-on-android%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
did you find any way to do this??
– shridutt kothari
Jun 9 '15 at 16:02