Last change
on this file since 3d64884 was 4d8825f, checked in by Dmitry Portnoy <dmp1488@…>, 4 years ago |
Add logic to make text files readable from inside a JAR
|
-
Property mode
set to
100644
|
File size:
734 bytes
|
Line | |
---|
1 | package main;
|
---|
2 |
|
---|
3 | import java.io.IOException;
|
---|
4 | import java.io.FileReader;
|
---|
5 | import java.io.InputStreamReader;
|
---|
6 | import java.io.BufferedReader;
|
---|
7 |
|
---|
8 | public class Utils {
|
---|
9 | private static boolean RUNNING_FROM_JAR = true;
|
---|
10 | private static Utils classLoaderReference = null;
|
---|
11 |
|
---|
12 | public static BufferedReader loadTextFile(final String fileName) throws IOException {
|
---|
13 | if (Utils.RUNNING_FROM_JAR) {
|
---|
14 | if (Utils.classLoaderReference == null) {
|
---|
15 | Utils.classLoaderReference = new Utils();
|
---|
16 | }
|
---|
17 | return new BufferedReader(new InputStreamReader(Utils.classLoaderReference.getClass().getResourceAsStream("/" + fileName)));
|
---|
18 | }
|
---|
19 | return new BufferedReader(new FileReader(fileName));
|
---|
20 | }
|
---|
21 | }
|
---|
Note:
See
TracBrowser
for help on using the repository browser.