作者ArcLaviz (小宋)
看板AndroidDev
标题[问题] 从server抓取档案
时间Mon Mar 26 15:10:19 2012
各位前辈好:
想请问一下,今天我在A手机上建立一个server,我B手机与跟A手机进行连线
在B手机上跑某个程式到一半,抓取A手机的档案做资料更新
但档案是有抓到没错,且档名正确,但内容却是空的或是错误的
不知有没有前辈遇过相似问题??
以下是我部份程式码
private void downloadFile() {
HttpClient client = new DefaultHttpClient();
HttpGet request = new HttpGet();
try {
File root = Environment.getExternalStorageDirectory();
BufferedOutputStream bout = new BufferedOutputStream(
new FileOutputStream(
root.getAbsolutePath() + "/audio.png"));
request.setURI(new URI(webpath3+":8443/console/audio.png"));
HttpResponse response = client.execute(request);
StatusLine status = response.getStatusLine();
//textView1.append("status.getStatusCode(): " + status.getStatusCode() + "\n");
Log.d("Test", "Statusline: " + status);
Log.d("Test", "Statuscode: " + status.getStatusCode());
HttpEntity entity = response.getEntity();
//textView1.append("length: " + entity.getContentLength() + "\n");
//textView1.append("type: " + entity.getContentType() + "\n");
Log.d("Test", "Length: " + entity.getContentLength());
Log.d("Test", "type: " + entity.getContentType());
entity.writeTo(bout);
bout.flush();
bout.close();
//textView1.append("OK");
} catch (URISyntaxException e) {
// TODO Auto-generated catch block
//textView1.append("URISyntaxException");
} catch (ClientProtocolException e) {
// TODO Auto-generated catch block
//textView1.append("ClientProtocolException");
} catch (IOException e) {
// TODO Auto-generated catch block
//textView1.append("IOException");
}
}
class processImageThread extends Thread
{
@Override
public void run()
{
// TODO Auto-generated method stub
super.run();
downloadFile();
DownloadFlag=1;
Log.i("tag","Download:"+DownloadFlag);
}
}
--
※ 发信站: 批踢踢实业坊(ptt.cc)
◆ From: 140.125.44.96
1F:→ ArcLaviz:已解决 感温感温 03/26 18:06