blog

리소스에 있는 PDF 파일을 로컬에 다운로드합니다.

다운로드 작업을 위해 위의 클래스를 사용하여 이 PDF를 다운로드하는 것이 목표입니다. 마지막으로 포스트맨으로 테스트 완료 다운로드 완료!...

Aug 16, 2025 · 2 min. read
シェア
package com.chint.tools;
import java.io.*;
/**
* 
* 
* @vsrsion 1.0
**/
public class FileDownloadUtil {
 /**
* 지정된 파일의 바이트 배열을 출력합니다.
*
* @param filePath 파일 경로
* @param os  
* @return
 */
public static void writeBytes(String filePath, OutputStream os) throws IOException
 {
 FileInputStream fis = null;
 try
 {
 File file = new File(filePath);
 if (!file.exists())
 {
 throw new FileNotFoundException(filePath);
 }
 fis = new FileInputStream(file);
 byte[] b = new byte;
 int length;
 while ((length = fis.read(b)) > 0)
 {
 os.write(b, 0, length);
 }
 }
 catch (IOException e)
 {
 throw e;
 }
 finally
 {
 if (os != null)
 {
 try
 {
 os.close();
 }
 catch (IOException e1)
 {
 e1.printStackTrace();
 }
 }
 if (fis != null)
 {
 try
 {
 fis.close();
 }
 catch (IOException e1)
 {
 e1.printStackTrace();
 }
 }
 }
 }
}
  • 대상 이 리소스/결과를 이 PDF로 다운로드하세요.

  • 다운로드 작업에는 위의 클래스를 사용하세요.
@GetMapping("/getDiscPdfFile")
public void downloadPdf(String discResult, HttpServletResponse response, HttpServletRequest request) {
 if (discResult == null) {
 Result.error("들어오는 디스크 측정값은 null일 수 없습니다.");
 } else if (!(discResult.equals("C") ||
 discResult.equals("CD") ||
 discResult.equals("CS") ||
 discResult.equals("D") ||
 discResult.equals("DC") ||
 discResult.equals("DI") ||
 discResult.equals("I") ||
 discResult.equals("ID") ||
 discResult.equals("IS") ||
 discResult.equals("S") ||
 discResult.equals("SC") ||
 discResult.equals("SI") ||
 discResult.equals("34-Ability")
 )) {
 Result.error("들어오는 디스크 측정값에 해당 유형이 없습니다.");
 }
 String fileNameStr = null;
 if (discResult.equals("34-Ability")) {
 fileNameStr = "34-Ability.pdf";
 } else {
 fileNameStr = "DISC-ResultReport-" + discResult + ".pdf";
 }
 String pdfFilePath = DiscResultController.class.getResource("/DISCResult/" + fileNameStr).getFile();
 try {
 FileDownloadUtil.writeBytes(pdfFilePath, response.getOutputStream());
 } catch (IOException e) {
 e.printStackTrace();
 log.error(" , e);
 }
}
  • 포스트맨으로 최종 테스트

다운로드 완료

Read next

JS 시간 서식 체계 요약

현재 JS에서 시간 서식을 지정하는 데는 다양한 옵션이 있지만, 구체적으로 어떤 것을 사용하려면 프로젝트 요구 사항과 해당 기술 스택을 살펴봐야 합니다. 다음은 일반적인 방법을 요약한 것입니다.

Aug 15, 2025 · 8 min read