美文网首页程序员
java 从本地拿取图片给前端显示

java 从本地拿取图片给前端显示

作者: 形影相随_371e | 来源:发表于2018-07-04 16:17 被阅读171次

直接从本地拿取图片给前端显示,直接给前端流数据:

public static void getPhoto(HttpServletResponse response, String imgUrl) throws Exception {
    String path = "你的路径" + imgUrl;
    File file = new File(path);
    FileInputStream fis;
    fis = new FileInputStream(file);

    long size = file.length();
    byte[] temp = new byte[(int) size];
    fis.read(temp, 0, (int) size);
    fis.close();
    byte[] data = temp;
    response.setContentType("image/png");
    OutputStream out = response.getOutputStream();
    out.write(data);
    out.flush();
    out.close();

}

我的博客

我的博客

相关文章

网友评论

    本文标题:java 从本地拿取图片给前端显示

    本文链接:https://www.haomeiwen.com/subject/nfaeuftx.html