Kotlin
[Kotlin] Spring 리소스(Resource) to File 파일변환
nineDeveloper
2021. 8. 1. 15:31
728x90
https://freedeveloper.tistory.com/465?category=956624
Spring, Kotlin 리소스(Resource) 파일 읽어오기, 다운로드
https://freedeveloper.tistory.com/193?category=808728 Spring, Java 리소스(Resource) 파일 읽어오기, 다운로드 Spring, Java 리소스(Resource) 파일 읽어오기, 다운로드 Maven 또는 Gradle 기반 프로젝트는 /s..
freedeveloper.tistory.com
Spring 리소스(Resource) 파일을 읽어와서 다운로드 하는 방법은 이전에 다루었었다
이번에는 읽어온 리소스(Resource) 파일을 File 로 변환하는 방법에 대해 기록해본다
변환하는 방법은 간단하다
아래와 같이 File 객체를 미리 생성하고 FileUtils.copyInputStreamToFile
기능으로 InputStream 형식을 File 로 변환해주면 된다
val fileName = "sampleUpload.xlsx"
val filePath = Paths.get("${File.separatorChar}file", fileName)
val file = File(fileName)
FileUtils.copyInputStreamToFile(javaClass.getResourceAsStream(filePath.toString()), file)
728x90