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