This commit is contained in:
32
app/src/main/java/gui/AssetManager.java
Normal file
32
app/src/main/java/gui/AssetManager.java
Normal file
@@ -0,0 +1,32 @@
|
||||
package gui;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
|
||||
public class AssetManager {
|
||||
|
||||
public static byte[] getResource(String name) {
|
||||
// we first search it in files
|
||||
File f = new File(name);
|
||||
if (f.exists()){
|
||||
FileInputStream fis;
|
||||
try {
|
||||
fis = new FileInputStream(f);
|
||||
return fis.readAllBytes();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
// then in the jar
|
||||
InputStream is = ClassLoader.getSystemResourceAsStream(name);
|
||||
try {
|
||||
return is.readAllBytes();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user