parent
9a06c52a8f
commit
aab87019ef
@ -0,0 +1,3 @@ |
||||
Manifest-Version: 1.0 |
||||
Created-By: 1.8.0_20 (Oracle Corporation) |
||||
|
@ -0,0 +1,11 @@ |
||||
package pkg; |
||||
|
||||
import pkg.res.Loader; |
||||
|
||||
public class Main { |
||||
public static void main(String[] args) { |
||||
Loader loader = new Loader(); |
||||
String resource = loader.getResource(); |
||||
System.out.println(resource); |
||||
} |
||||
} |
@ -0,0 +1,25 @@ |
||||
package pkg.res; |
||||
|
||||
import java.io.File; |
||||
import java.io.FileInputStream; |
||||
import java.net.URL; |
||||
|
||||
public class Loader { |
||||
public String getResource() { |
||||
URL resource = this.getClass().getClassLoader().getResource("pkg/res/resource.txt"); |
||||
if(resource == null) { |
||||
throw new RuntimeException("Resource missing"); |
||||
} else { |
||||
try { |
||||
File e = new File(resource.toURI()); |
||||
byte[] bytes = new byte[(int)e.length()]; |
||||
FileInputStream stream = new FileInputStream(e); |
||||
stream.read(bytes); |
||||
stream.close(); |
||||
return new String(bytes, "UTF-8"); |
||||
} catch (Exception var5) { |
||||
throw new RuntimeException("Resource load failed", var5); |
||||
} |
||||
} |
||||
} |
||||
} |
Loading…
Reference in new issue