Rumah > Soal Jawab > teks badan
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
怎么解决 流着一块不太熟悉 求代码