upravena kompilace presun do složky resurces
parent
0c50656f13
commit
92cc447771
|
|
@ -1,29 +1,30 @@
|
|||
package jnet.lib;
|
||||
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.FileReader;
|
||||
import java.io.FileWriter;
|
||||
import java.io.IOException;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import org.apache.commons.configuration2.PropertiesConfiguration;
|
||||
import org.apache.commons.configuration2.ex.ConfigurationException;
|
||||
|
||||
public class PropertiesManager {
|
||||
|
||||
private PropertiesConfiguration config;
|
||||
private String filePath;
|
||||
private String file;
|
||||
|
||||
// Konstruktor pro inicializaci s cestou k souboru
|
||||
public PropertiesManager(String filePath) {
|
||||
this.filePath = filePath;
|
||||
public PropertiesManager(String file) {
|
||||
this.file = file;
|
||||
this.config = new PropertiesConfiguration();
|
||||
}
|
||||
|
||||
public void load() throws FileException, ConfigException {
|
||||
try {
|
||||
// Načtení existující konfigurace, pokud soubor existuje
|
||||
config.read(new FileReader(filePath));
|
||||
try (InputStream input = getClass().getClassLoader().getResourceAsStream(file)) {
|
||||
if (input == null) {
|
||||
throw new FileException("Soubor config.properties nebyl nalezen.");
|
||||
}
|
||||
config.read(new InputStreamReader(input, StandardCharsets.UTF_8));
|
||||
} catch (ConfigurationException ex) {
|
||||
throw new ConfigException("Chyba konfigurace");
|
||||
} catch (IOException ex) {
|
||||
|
|
@ -43,7 +44,7 @@ public class PropertiesManager {
|
|||
|
||||
// Metoda pro uložení konfigurace do souboru
|
||||
public void save() {
|
||||
try (FileWriter writer = new FileWriter(filePath)) {
|
||||
try (FileWriter writer = new FileWriter(file)) {
|
||||
// Použití FileWriter pro zápis do souboru
|
||||
config.write(writer);
|
||||
LogFile.printInfo("Konfigurace byla uspesne ulozena.");
|
||||
|
|
@ -90,7 +91,7 @@ public class PropertiesManager {
|
|||
super(message);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public class ConfigException extends Exception {
|
||||
|
||||
public ConfigException(String message) {
|
||||
|
|
|
|||
Loading…
Reference in New Issue