本文继续讲解andriod网络方面问题。本文主要在Eclipse上搭建服务器端。
同上篇,本文tomcat版本7.0,servlet 3.0不需要在web.xml下注册xml文件。
本文实现的内容较简单,在服务器在磁盘上读取一个pdf(其他文件也行),返回一个流文件给客户端。
服务器端的代码如下:
<p>protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
//String pathString="F:\\作业\\基于ARM11的嵌入式系统开发方法.docx";
//要下载的文件路径,本文为绝对路径
request.setCharacterEncoding("utf-8");
response.setCharacterEncoding("utf-8");
//String pathString="D:\\我的文档\\桌面\\新建文件夹<a target=_blank href="file://\\Android">\\Android</a> 4编程入门经典.pdf";
String pathString="D:\\我的文档\\桌面\\新建文件夹 (2)\\Hello四川.txt";
InputStream inputStream=null;
OutputStream outputStream=null;
File file=new File(pathString);
inputStream=new BufferedInputStream(new FileInputStream(f