InputStream is = entity.getContent();String filePath = "sample.txt";FileOutputStream fos = new FileOutputStream(new File(filePath));int inByte;while((inByte = is.read()) != -1) fos.write(inByte);is.close();fos.close();
编辑:
您还可以使用BufferedOutputStream和BufferedInputStream来加快下载速度:
BufferedInputStream bis = new BufferedInputStream(entity.getContent());String filePath = "sample.txt";BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream(new File(filePath)));int inByte;while((inByte = bis.read()) != -1) bos.write(inByte);bis.close();bos.close();



