Issue
I've a problem with android and Storage Options (Internal Storage).
I added a SSL certificate in the "raw" directory and i want to write in, into the storage.
In the moment I'm trying it with this code snippet:
InputStream is = SA.getResources().openRawResource(R.raw.myResource);
ByteArrayOutputStream buffer = new ByteArrayOutputStream();
int nRead;
byte[] data = new byte[16384];
while ((nRead = is.read(data, 0, data.length)) != -1)
{
buffer.write(data, 0, nRead);
}
buffer.flush();
FileOutputStream fos = SA.openFileOutput("Resource.crt", 0);
fos.write(buffer.toByteArray());
fos.close();
is.close();
buffer.close();
File f = new File(this.fileList()[0]);
if(f.exists())
{
Log.v("File:", "Found");
}
else
{
Log.v("File:", "Not found");
}
My File isn't found. I don't know why.
Solution
I believe fileList
is just returning the filename, but you also need the directory try :
File f = new File(context.getFilesDir(), filename);
if(f.exists()){
...
Read here :
http://developer.android.com/training/basics/data-storage/files.html#WriteInternalStorage
Answered By - Emil Davtyan
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.