服务器如何显示接收的数据,如何从服务器接收数据?

/** this function will download content from the internet */

static int writeData(String fileurl, boolean append, String path,

String filename, Activity mContext) throws CustomException {

URL myfileurl = null;

ByteArrayBuffer baf = null;

HttpURLConnection conn = null;

String mimeType="";

final int length;

try {

myfileurl = new URL(fileurl);

} catch (MalformedURLException e) {

e.printStackTrace();

}

try {

conn = (HttpURLConnection) myfileurl

.openConnection();

conn.setDoInput(true);

conn.connect();

conn.setConnectTimeout(100000);

length = conn.getContentLength();

mimeType=conn.getContentType().toString();

System.out.println("Extension..."+mimeType);

if(mimeType.equalsIgnoreCase("application/vnd.adobe.adept+xml") || mimeType.equalsIgnoreCase("text/html; charset=utf-8"))

return 0;

if (length > 0) {

InputStream is = conn.getInputStream();

BufferedInputStream bis = new BufferedInputStream(is);

baf = new ByteArrayBuffer(1000);

int current = 0;

while ((current = bis.read()) != -1) {

try {

baf.append((byte) current);

mBufferError=false;

} catch (Exception e){

// TODO: handle exception

mBufferError=true;

e.printStackTrace();

throw new CustomException("@@@ memory problem ", "Buffer Error");

}

}

}

} catch (IOException e) {

mBufferError=true;

e.printStackTrace();

}

try{

if(conn.getResponseCode()==200 && mBufferError==false)

{

path = path + "/" + filename;

boolean appendData = append;

FileOutputStream foutstream;

File file = new File(path);

boolean exist = false;

try {

if (appendData)

exist = file.exists();

else

exist = file.createNewFile();

} catch (IOException e) {

try {

return 1;

} catch (Exception err) {

Log.e("SAX", err.toString());

}

}

if (!appendData && !exist) {

} else if (appendData && !exist) {

} else {

try {

foutstream = new FileOutputStream(file, appendData);

foutstream.write(baf.toByteArray());

foutstream.close();

} catch (Exception e) {

e.printStackTrace();

}

}

}

}catch (Exception e) {

// TODO: handle exception

throw new CustomException("@@@ I/O problem ", "I/O Error");

}

return 1;

}

下载一次完整的搜索带扩展名(名为.3gp)文件的视频 希望它有助于

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值