我有 3 个班级来处理所有配置。(2 类 2000 行)
我想添加对 UTF-8 字符的支持,而不需要从 0 编写所有代码;/
我展示了我最小的课程(还没有完成,我不想用 1400 行发送垃圾邮件:))实际上只有两个变量:
package com.gmail.bukkitSmerf.professionalWarns;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import org.bukkit.configuration.InvalidConfigurationException;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.configuration.file.YamlConfiguration;
public class LangHandler {
private static String lWarns_DeletedWarnAddon, lWarns_ExpiredWarnAddon;
public static String getlWarns_DeletedWarnAddon() {
return lWarns_DeletedWarnAddon;
}
public static String getlWarns_ExpiredWarnAddon() {
return lWarns_ExpiredWarnAddon;
}
public void createConfig(boolean forceConfigUpdate) {
try {
String langFileName = "languageEN.yml";
InputStream input = ProfessionalWarns
.getPluginResource_languageEN();
if (ConfigHandler.getcGeneral_Language().equalsIgnoreCase("PL")) {
langFileName = "languagePL.yml";
input = ProfessionalWarns.getPluginResource_languagePL();
}
File langFile = new File(ProfessionalWarns.getPluginDataFolder(),
langFileName);
if (!langFile.exists()) {
langFile.getParentFile().mkdirs();
ConfigHandler.copy(input, langFile);
}
YamlConfiguration lang = new YamlConfiguration();
FileConfiguration rawLang = YamlConfiguration
.loadConfiguration(input);
lang.load(langFile);
lWarns_DeletedWarnAddon = lang.getString("Warns.DeletedWarnAddon",
rawLang.getString("Warns.DeletedWarnAddon"));
lWarns_ExpiredWarnAddon = lang.getString("Warns.ExpiredWarnAddon",
rawLang.getString("Warns.ExpiredWarnAddon"));
if (ConfigHandler.iscGeneral_AutoUpdateConfigs()
|| forceConfigUpdate) {
FileWriter fw = new FileWriter(langFile);
PrintWriter pw = new PrintWriter(fw);
pw.flush();
pw.write("Warns:\n DeletedWarnAddon: '"
+ lWarns_DeletedWarnAddon + "'\n ExpiredWarnAddon: '"
+ lWarns_ExpiredWarnAddon + "'");
pw.close();
}
} catch (IOException | InvalidConfigurationException e) {
e.printStackTrace();
ProfessionalWarns
.logWarning("Error when trying create/write/reload language file!");
}
}
}
我不知道如何在这里使用那个 UTF-8。
我也不想删除任何功能。
如果可以的话,也给我一些关于该代码的建议:)
//对不起我的英语不好