java用流的方式加載圖片


前端:

<img ng-show="photo" class="vertical_b" id="photoImg" src="http://localhost:9999/manage-admin/filemanager/prevViewByPath.action?filePath=cf532711-6ba8-4259-8c30-1dbb13fe3a82.jpg">

后端:

/**
     * @throws IOException 
     * @throws FileNotFoundException 
     * 功能:預覽
     * @param
     * @return
     * @throws   
     */
    public String prevViewByPath() throws IOException{
        String catalinaHome = filePathConfig.getFileUploadPath();
        String targetDirectory = catalinaHome + "/upload/";
        String filedownload = targetDirectory + filePath;
        File f = new File(filedownload);
        if(!f.exists()){
            return null;
        }
        FileInputStream fis = new FileInputStream(f);
        OutputStream out = getResponse().getOutputStream();
        byte[] bs = new byte[1024];
        while ((fis.read(bs) != -1)) {
            out.write(bs);
        }
        out.flush();
        out.close();
        out = null;
        fis.close();
        return null;
    }

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM