byte[] blob = userinfo.getPhoto()
if(blob!=null){
response.reset() response.setContentType("image/"+dat) OutputStream toClient = response.getOutputStream() try {toClient.write(blob) } catch (Exception e) {e.printStackTrace() }finally{toClient.flush() toClient.close() } response.flushBuffer() }
写数据库
byte[] bFile = new byte[(int) files[0].length()]FileInputStream fileInputStream = new FileInputStream(files[0])fileInputStream.read(bFile)fileInputStream.close()userinfo.setPhotoname(photoName[0])userinfo.setPhoto(bFile)
userdao.save(userinfo)
我这个是java的,不知道和你的一不一样
简单实现:HtmlRequest类的内容:
[java] view plaincopy
package com.capinfotech.net
import java.io.ByteArrayOutputStream
import java.io.IOException
import java.io.InputStream
import java.net.HttpURLConnection
import java.net.URL
public class HtmlRequest {
public static void main(String[] args) throws IOException {
URL url = new URL("http://www.163.com/")
HttpURLConnection conn = (HttpURLConnection)url.openConnection()
InputStream inputStream = conn.getInputStream() //通过输入流获得网站数据
byte[] getData = readInputStream(inputStream)//获得网站的二进制数据
String data = new String(getData, "gb2312")
System.out.println(data)
}
public static byte[] readInputStream(InputStream inputStream) throws IOException {
byte[] buffer = new byte[1024]
int len = 0
ByteArrayOutputStream bos = new ByteArrayOutputStream()
while((len = inputStream.read(buffer)) != -1) {
bos.write(buffer, 0, len)
}
bos.close()
return bos.toByteArray()
}
}
这样就能获得http://www.163.com的内容,在控制台会打印输出
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)