twodcraft/src/main/java/cz/jzitnik/tui/ResourceLoader.java

28 lines
828 B
Java

package cz.jzitnik.tui;
import java.io.IOException;
import java.io.InputStream;
import java.nio.charset.StandardCharsets;
import lombok.extern.slf4j.Slf4j;
@Slf4j
public class ResourceLoader {
public static String loadResource(String fileName) {
log.debug("Loading resource: {}", "textures/" + fileName);
try (InputStream inputStream = ResourceLoader.class.getClassLoader()
.getResourceAsStream("textures/" + fileName)) {
if (inputStream == null) {
// If the file is not found, return null
return null;
}
byte[] bytes = inputStream.readAllBytes();
return new String(bytes, StandardCharsets.UTF_8);
} catch (IOException e) {
e.printStackTrace();
return null;
}
}
}