视屏转换成流输出给页面

FileInputStream fis = null;
    OutputStream os = null ;
    try {
        PropertyHelper ph = new PropertyHelper();
        Properties propertiesInstance = ph.getInstance();
        String videoPath = propertiesInstance.getProperty("videoPath")+id+".mp4";//路径
        fis = new FileInputStream(videoPath);
        int size = fis.available(); // 得到文件大小
        byte data[] = new byte[size];
        fis.read(data); // 读数据
        fis.close();
        fis = null;
        response.setContentType("video/mp4"); // 设置返回的文件类型
            os = response.getOutputStream();
            os.write(data);
            os.flush();
            os.close();
            os = null;
        
    } catch (Exception e) {
        e.printStackTrace();
        try {
        if(os!=null){
                os.close();
            os = null;
        }
        if(fis != null){
                fis.close();
                fis = null;
        }
            } catch (IOException e1) {
                e1.printStackTrace();
            }
    }

小文件不会出问题 大文件在os.write(data); 报错Connection reset by peer: socket write error

怎么解决 流着一块不太熟悉 求代码

阅读 4.7k
1 个回答
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题