Add config file verification and type detection
parent
b67fa7fd9f
commit
0cca0384c9
|
|
@ -0,0 +1,43 @@
|
|||
public class config_editor {
|
||||
public static String config_file_path;
|
||||
public static Enum<ConfigFileType> config_file_type;
|
||||
static java.io.File config_file;
|
||||
|
||||
enum ConfigFileType {
|
||||
JSON,
|
||||
XML
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
config_file_path = args[0];
|
||||
verify_config_file();
|
||||
config_file_type();
|
||||
}
|
||||
|
||||
static void verify_config_file() {
|
||||
if (config_file_path == null || config_file_path.isEmpty()) {
|
||||
System.err.println("Config file path is not provided.");
|
||||
return;
|
||||
}
|
||||
|
||||
config_file = new java.io.File(config_file_path);
|
||||
|
||||
if (!config_file.exists()) {
|
||||
System.err.println("Config file does not exist: " + config_file_path);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
static void config_file_type() {
|
||||
if (config_file_path.endsWith(".json")) {
|
||||
config_file_type = ConfigFileType.JSON;
|
||||
System.out.println("JSON config file detected.");
|
||||
} else if (config_file_path.endsWith(".xml")) {
|
||||
config_file_type = ConfigFileType.XML;
|
||||
System.out.println("XML config file detected.");
|
||||
} else {
|
||||
System.err.println("Unsupported config file type. Please provide a .json or .xml file.");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Loading…
Reference in New Issue