String http = "http://192.168.1.154:8081/onLineSearchReport/images/upload/tspecial/bg_02.gif";
URL url = new URL(http);
URLConnection conn = url.openConnection();
conn.connect();
InputStream in = conn.getInputStream();
Bitmap map = BitmapFactory.decodeStream(in);
image01.setBackgroundDrawable(new BitmapDrawable(map));在运行的时候,执行到InputStream in = conn.getInputStream();行代码的时候抛出异常。执行不过去。
在IE浏览器当中输入地址能够获取到图片。如果使用HttpClient.....方法的时候,
HttpPost方法调用也会出错,哪位大侠帮帮忙啊??
URL url = new URL(http);
URLConnection conn = url.openConnection();
conn.connect();
InputStream in = conn.getInputStream();
Bitmap map = BitmapFactory.decodeStream(in);
image01.setBackgroundDrawable(new BitmapDrawable(map));在运行的时候,执行到InputStream in = conn.getInputStream();行代码的时候抛出异常。执行不过去。
在IE浏览器当中输入地址能够获取到图片。如果使用HttpClient.....方法的时候,
HttpPost方法调用也会出错,哪位大侠帮帮忙啊??
URL image_url = new URL("http://192.168.1.154:8081/onLineSearchReport/images/upload/tspecial/bg_02.gif");
URLConnection image_conn = image_url.openConnection();
image_conn.connect();
int image_file_size = image_conn.getContentLength();
if(image_file_size <= 0) return;
// local_path + File.separator + image_file_name是你本地保存图片文件的名字,比如/sdcard/bg_02.gif
File image_file = new File(local_path + File.separator + image_file_name);
InputStream image_is = image_conn.getInputStream();
FileOutputStream image_fos = new FileOutputStream(image_file);
byte image_buffer[] = new byte[1024];
int image_number_read_bytes;
while((image_number_read_bytes = image_is.read(image_buffer)) != -1)
{
image_fos.write(image_buffer, 0, image_number_read_bytes);
}
image_fos.flush();
image_is.close();
image_fos.close();
你单步调式一下吧。上面是我在项目中用到的代码,应该不会错的。你可以用手机上的文件管理器去查看一下,以确定图片是否真的没有被保存?读本地文件不需要URL,获取服务器上的是必须要URL的。