Reputation: 1682
I am trying to read the files from URL and write into my sdcard. As it is working good with the other files like .js .css and .txt files etc... But it is not working with .png .jpg .bmp and .gif. My code for this is
String path = dir + value;
File localConfigfile = new File(
Environment.getExternalStorageDirectory()
+ "/Avalon/assets/www/" + path);
String responseString = RequestMgr.GetWebSource(DomainName
+ "/" + Heirarchy + "/" + Serverpath);
FileOutputStream out;
if (localConfigfile.exists()) {
localConfigfile.delete();
out = new FileOutputStream(localConfigfile);
out.write(responseString.getBytes());
}
}
Please help me here i am struck in this
Upvotes: 1
Views: 666
Reputation: 1682
private void storeImage(Bitmap image) {
File pictureFile = getOutputMediaFile();
if (pictureFile == null) {
Log.d(TAG,
"Error creating media file, check storage permissions: ");// e.getMessage());
return;
}
try {
FileOutputStream fos = new FileOutputStream(pictureFile);
image.compress(Bitmap.CompressFormat.PNG, 90, fos);
fos.close();
} catch (FileNotFoundException e) {
Log.d(TAG, "File not found: " + e.getMessage());
} catch (IOException e) {
Log.d(TAG, "Error accessing file: " + e.getMessage());
} }
Upvotes: 1
Reputation: 51
Try using reading a file using bitmap. It will be good option if you read using bitmap and URI for performance
Upvotes: 1