컨텍스트이면 ServletOutputStream을 사용할 수 있습니다. 여기서 리소스 경로 정보는 HTTP의 추가 경로 정보로 전달됩니다.
final ServletOutputStream out = res.getOutputStream();
res.setContentType("application/octet-stream");
String file = req.getPathInfo();
if (file == null) {
out.println("Extra path info was null; should be a resource to view");
return;
}
// Convert the resource to a URL
URL url = getServletContext().getResource(file);
if (url == null) {
out.println("Resource " + file + " not found");
return;
}
//Serve the file
InputStream in = url.openStream();
byte[] buf = new byte[4 * 1024]; // 4K buffer
int bytesRead;
while ((bytesRead = in.read(buf)) != -1) {
out.write(buf, 0, bytesRead);
}
이 파일의 길이는 무제한 출력입니까? 그리고 주어진 스 니펫에 따라 클라이언트 스 니펫은 그 다음에 있어야합니다. – user592704
어쨌든, 고마워. 그것은 나에게 코딩 스타일 비전을 주었다 :) – user592704