44import ru .javawebinar .basejava .storage .Storage ;
55
66import java .io .File ;
7- import java .io .FileInputStream ;
87import java .io .IOException ;
98import java .io .InputStream ;
109import java .util .Properties ;
1110
1211public class Config {
13- private static final File PROPS = new File ( getHomeDir (), "config \\ resumes.properties") ;
12+ private static final String PROPS = "/ resumes.properties" ;
1413 private static final Config INSTANCE = new Config ();
1514
1615 private final File storageDir ;
@@ -21,13 +20,13 @@ public static Config get() {
2120 }
2221
2322 private Config () {
24- try (InputStream is = new FileInputStream (PROPS )) {
23+ try (InputStream is = Config . class . getResourceAsStream (PROPS )) {
2524 Properties props = new Properties ();
2625 props .load (is );
2726 storageDir = new File (props .getProperty ("storage.dir" ));
2827 storage = new SqlStorage (props .getProperty ("db.url" ), props .getProperty ("db.user" ), props .getProperty ("db.password" ));
2928 } catch (IOException e ) {
30- throw new IllegalStateException ("Invalid config file " + PROPS . getAbsolutePath () );
29+ throw new IllegalStateException ("Invalid config file " + PROPS );
3130 }
3231 }
3332
@@ -38,13 +37,4 @@ public File getStorageDir() {
3837 public Storage getStorage () {
3938 return storage ;
4039 }
41-
42- private static File getHomeDir () {
43- String prop = System .getProperty ("homeDir" );
44- File homeDir = new File (prop == null ? "." : prop );
45- if (!homeDir .isDirectory ()) {
46- throw new IllegalStateException (homeDir + " is not directory" );
47- }
48- return homeDir ;
49- }
5040}
0 commit comments