new Thread(new Runnable() {
//开始
public void run() {
try {
File file=new File(Environment.getExternalStorageDirectory()+"/.msy/msy.apk");
file.createNewFile();
FileOutputStream outputStream=new FileOutputStream(file);
HttpPost httpPost=new HttpPost("http://192.168.1.213:8080/MAsy/servlet/downServlet");//这样用post,服务器的servlet也要用post
HttpClient httpClient = new DefaultHttpClient();
HttpResponse response=httpClient.execute(httpPost);
InputStream inputStream=response.getEntity().getContent();//获取流
buffer=new byte[1024];//缓冲
int leng;
while((leng=inputStream.read(buffer)) != -1){
outputStream.write(buffer,0,leng);
System.out.println("w");
}
inputStream.close();
outputStream.flush();
outputStream.close();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
}).start();
//开始
public void run() {
try {
File file=new File(Environment.getExternalStorageDirectory()+"/.msy/msy.apk");
file.createNewFile();
FileOutputStream outputStream=new FileOutputStream(file);
HttpPost httpPost=new HttpPost("http://192.168.1.213:8080/MAsy/servlet/downServlet");//这样用post,服务器的servlet也要用post
HttpClient httpClient = new DefaultHttpClient();
HttpResponse response=httpClient.execute(httpPost);
InputStream inputStream=response.getEntity().getContent();//获取流
buffer=new byte[1024];//缓冲
int leng;
while((leng=inputStream.read(buffer)) != -1){
outputStream.write(buffer,0,leng);
System.out.println("w");
}
inputStream.close();
outputStream.flush();
outputStream.close();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
}).start();