I am struggling with this, if the image doesnt exist hello.jpg it does
create a new file, but when i execute the line of FileOutputStream out =
new FileOutputStream(file);, i get a filenotfoundexception.
public static Bitmap getImage(String fileUrl)
{
Bitmap bitmap = null;
InputStream in = null;
URL url;
// Check to see if image allready exists
String imgName = fileUrl.substring(fileUrl.lastIndexOf(/)+1);
String sdPath = /Barfly/+imgName;
File imgFile = new File(sdPath);
if (imgFile.exists())
{
bitmap = BitmapFactory.decodeFile(sdPath);
}
else
{
try {
url = new URL(fileUrl);
URLConnection ucon = url.openConnection();
in = ucon.getInputStream();
bitmap = BitmapFactory.decodeStream(in);
in.close();
File path = Environment.getExternalStorageDirectory();
File dir = File(path,Barfly);
File file = new File(dir,imgName);
boolean result = file.mkdirs();
result = file.createNewFile();
try
{
FileOutputStream out = new FileOutputStream(file);
bitmap.compress(Bitmap.CompressFormat.JPEG, 90, out);
}
catch (Exception e) {
e.printStackTrace();
}
}
catch (MalformedURLException e)
{
e.printStackTrace();
}
catch (FileNotFoundException e)
{
e.printStackTrace();
}
catch (IOException e)
{
}
catch (Exception e)
{
e.printStackTrace();
}
}
return bitmap;
}
Charles Berman
313.790.9851
www.charlesberman.com
--
You received this message because you are subscribed to the Google
Groups Android Developers group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en