`
wjboy49
  • 浏览: 274375 次
  • 性别: Icon_minigender_1
  • 来自: 湖南岳阳
社区版块
存档分类
最新评论

servlet 读取图片

    博客分类:
  • java
阅读更多

    String path = "F:/wjboy/photo/20010.jpg";
        System.out.println(path);
        response.setContentType("text/html");
        ObjectOutputStream picStream = null;
        try {
            FileInputStream hFile = new FileInputStream(path); // 以byte流的方式打开文件
            int i = hFile.available(); // 得到文件大小
            byte data[] = new byte[i];
            hFile.read(data); // 读数据
            hFile.close();
            OutputStream toClient = response.getOutputStream();
            toClient.write(data);
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            if (picStream != null) {
                try {
                    picStream.flush();
                    picStream.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
        return null;

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics