[問題] 從server抓取檔案
各位前輩好:
想請問一下,今天我在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
→
03/26 18:06, , 1F
03/26 18:06, 1F