/**
* 将文件输出到浏览器上
* @param fileIO 文件的输入流
* @param responseOS 响应信息的输出流
*/
public static void writeBytes(InputStream fileIO, OutputStream responseOS) throws IOException {
try {
byte[] b = new byte[1024];
int length;
while ((length = fileIO.read(b)) > 0) {
responseOS.write(b, 0, length);
}
}
catch (IOException e) {
e.printStackTrace();
}
finally {
if(responseOS != null){
responseOS.close();
}
if(fileIO != null){
fileIO.close();
}
}
}
/**
* 将文件输出到指定路径中
* @param input 文件的输出流
* @param filePath 文件的输出路径
*/
public static void writeToLocal(InputStream input,String filePath) throws IOException {
int index;
byte[] bytes = new byte[1024];
FileOutputStream downloadFile = new FileOutputStream(filePath);
while ((index = input.read(bytes)) != -1) {
downloadFile.write(bytes, 0, index);
downloadFile.flush();
}
input.close();
downloadFile.close();
}
File文件输出到浏览器上或指定文件夹中
最新推荐文章于 2024-05-07 11:39:23 发布