|
你的需求是怎样的 打算传输哪些信息
|
|
|
我是做文件上传下载,服务端是java写的,客户端是ios,下载客户端不知道怎么写,谢谢回复,还请帮忙理理思路 |
|
|
40分 |
/**
* http下载
*/
public static boolean httpDownload(String httpUrl, String saveFile) {
// 下载网络文件
int bytesum = 0;
int byteread = 0;
URL url = null;
try {
url = new URL(httpUrl);
} catch (MalformedURLException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
return false;
}
FileOutputStream fs = null;
URLConnection conn = null;
InputStream inStream = null;
try {
conn = url.openConnection();
inStream = conn.getInputStream();
fs = new FileOutputStream(saveFile);
byte[] buffer = new byte[1204];
while ((byteread = inStream.read(buffer)) != -1) {
bytesum += byteread;
// System.out.println(bytesum);
fs.write(buffer, 0, byteread);
}
return true;
} catch (FileNotFoundException e) {
e.printStackTrace();
return false;
} catch (IOException e) {
e.printStackTrace();
return false;
} finally {
if (null != fs) {
try {
fs.close();
} catch (IOException e) {
e.printStackTrace();
}
}
if (null != inStream) {
try {
inStream.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
以上是java实现 搜索 ios http 下载 这是其中一个结果 http://blog.sina.com.cn/s/blog_6ec3c9ce01019bcx.html |