Initial commit
This commit is contained in:
26
src/main/java/main/YamlLoad/yaml.java
Normal file
26
src/main/java/main/YamlLoad/yaml.java
Normal file
@@ -0,0 +1,26 @@
|
||||
package main.YamlLoad;
|
||||
|
||||
import org.yaml.snakeyaml.Yaml;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.InputStream;
|
||||
import java.util.Map;
|
||||
|
||||
public class yaml {
|
||||
public String StringYaml(String YamlFile, String GetKey) {
|
||||
String YamlValue = "";
|
||||
|
||||
try (InputStream input = new FileInputStream(YamlFile)) {
|
||||
Yaml yaml = new Yaml();
|
||||
Map<String, Object> data = yaml.load(input);
|
||||
|
||||
if (data != null && data.containsKey(GetKey)) {
|
||||
Object value = data.get(GetKey);
|
||||
YamlValue = value != null ? value.toString() : "";
|
||||
}
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException("读取YAML文件失败: " + e.getMessage(), e);
|
||||
}
|
||||
|
||||
return YamlValue;
|
||||
}
|
||||
}
|
||||
34
src/main/java/main/main.java
Normal file
34
src/main/java/main/main.java
Normal file
@@ -0,0 +1,34 @@
|
||||
package main;
|
||||
|
||||
import main.YamlLoad.yaml;
|
||||
|
||||
public class main {
|
||||
public boolean debug = true;
|
||||
|
||||
public static void main(String[] args) {
|
||||
boolean debug = new main().debug;
|
||||
if (debug) {
|
||||
// 打印当前运行环境的系统类型和版本
|
||||
System.out.println("系统类型: " + System.getProperty("os.name") + " " + "系统版本: " + System.getProperty("os.version"));
|
||||
System.out.println("Java版本: " + System.getProperty("java.version"));
|
||||
System.out.println("Java Vendor版本: " + System.getProperty("java.vendor"));
|
||||
System.out.println("Java Home位置: " + System.getProperty("java.home"));
|
||||
System.out.println("Java Class位置: " + System.getProperty("java.class.path"));
|
||||
System.out.println("运行的用户: " + System.getProperty("user.name"));
|
||||
// 获取当前的运行目录
|
||||
System.out.println("当前运行目录: " + System.getProperty("user.dir"));
|
||||
}
|
||||
System.out.println("\nHello World!");
|
||||
new main().YamlTest();
|
||||
}
|
||||
|
||||
private void YamlTest() {
|
||||
yaml y = new yaml();
|
||||
String YamlValue = y.StringYaml("test.yml", "test");
|
||||
System.out.println(YamlValue);
|
||||
}
|
||||
|
||||
public static String Version() {
|
||||
return "1.0.0";
|
||||
}
|
||||
}
|
||||
4
src/main/java/main/util/tools.java
Normal file
4
src/main/java/main/util/tools.java
Normal file
@@ -0,0 +1,4 @@
|
||||
package main.util;
|
||||
|
||||
public class tools {
|
||||
}
|
||||
Reference in New Issue
Block a user