URL url = new URL ("http://mms.tom.com/image_128x128/36095.gif"); InputStream is = url.openStream (); BufferedReader br = new BufferedReader (new InputStreamReader (is));
StringBuffer append(char c) Appends the string representation of the char argument to this string buffer. StringBuffer append(int i) Appends the string representation of the int argument to this string buffer. 试试看(33在ASCII表中是“!”): sb.append(33); sb.append((char)33); 结果是什么?同时你犯了一个错误StringBuffer固然比String要好。但是那2个类都不是作为数据存储的好对象! 尤其是在io相关的时候,推荐你用byte[]或者ByteArrayOutputStream
估计不行。
还是得存储再你的项目文件夹里面才行
InputStream is = url.openStream ();
BufferedReader br = new BufferedReader (new InputStreamReader (is));
试试 楼上的办法咋样
URI uri = new URI("http://mms.tom.com/image_128x128/36095.gif");
File file = new File(uri);可以吗
{
InputStream ins = new FileInputStream(file);
byte[] bytes = new byte[ ins.available() ];
ins.read(bytes);
ins.close();
ins = null;
return bytes;
}
上面这样的方法得到一个字节数组,和我下面得到的数组,会有什么不同呢,
URL url = new URL("http://218.204.253.99:8090/xxx/yyy/9038.jpg");
InputStream imageInput = url.openStream();
int ch = -1;
StringBuffer sb = new StringBuffer();
while((ch = imageInput.read())!= -1){
System.out.println("ok");
sb.append(ch);
}byte[] bytes = sb.getBytes();有什么不同呢?
Appends the string representation of the char argument to this string buffer. StringBuffer append(int i)
Appends the string representation of the int argument to this string buffer. 试试看(33在ASCII表中是“!”):
sb.append(33);
sb.append((char)33);
结果是什么?同时你犯了一个错误StringBuffer固然比String要好。但是那2个类都不是作为数据存储的好对象!
尤其是在io相关的时候,推荐你用byte[]或者ByteArrayOutputStream