java获取文件流

@RequestMapping(value = "preView", method = RequestMethod.GET)
public void preView(HttpServletResponse response){
File file = new File("C:\\Users\\admin\\Desktop\\新建文本文档.txt");
if (file.exists()){
byte[] data = null;
try {
FileInputStream input = new FileInputStream(file);
data = new byte[input.available()];
input.read(data);
response.getOutputStream().write(data);
input.close();
} catch (Exception e) {
System.out.println(e);
}
}else{
return;
}

}
posted on 2022-06-09 16:35  IT-QI  阅读(2949)  评论(0编辑  收藏  举报