salmanoe f1ea106955 Update SlipGajiService
Pembuatan service generate dan download template slip gaji rekap seluruh pegawai
2023-02-01 08:32:48 +07:00

32 lines
861 B
Java

package com.jasamedika.medifirst2000.util;
import java.io.FileNotFoundException;
import java.net.MalformedURLException;
import java.nio.file.Path;
import java.nio.file.Paths;
import org.springframework.core.io.Resource;
import org.springframework.core.io.UrlResource;
import org.springframework.stereotype.Component;
/**
* @author salmanoe
* @since Jan 31, 2023
*/
@Component
public class ResourceUtils {
public static Resource loadFile(String fileName) throws Exception {
try {
Path filePath = Paths.get(fileName).toAbsolutePath().normalize();
Resource resource = new UrlResource(filePath.toUri());
if (resource.exists()) {
return resource;
} else {
throw new FileNotFoundException("File not found " + fileName);
}
} catch (MalformedURLException e) {
throw new FileNotFoundException("File not found " + fileName);
}
}
}