本文整理匯總了Java中com.badlogic.gdx.files.FileHandle.reader方法的典型用法代碼示例。如果您正苦於以下問題:Java FileHandle.reader方法的具體用法?Java FileHandle.reader怎麽用?Java FileHandle.reader使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類com.badlogic.gdx.files.FileHandle
的用法示例。
在下文中一共展示了FileHandle.reader方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: read
import com.badlogic.gdx.files.FileHandle; //導入方法依賴的package包/類
public static boolean read() {
FileHandle fileHandle = Compatibility.get().getBaseFolder().child("settings.json");
try {
Reader reader = fileHandle.reader();
JsonObject json = Json.parse(reader).asObject();
reader.close();
for (Member member : json) {
Setting setting = set.settings.get(member.getName());
setting.readJson(member.getValue());
}
return true;
} catch (Exception e) {
Log.error("Failed to read settings", e);
fileHandle.delete();
return false;
}
}
示例2: read
import com.badlogic.gdx.files.FileHandle; //導入方法依賴的package包/類
public static boolean read() {
FileHandle fileHandle = Compatibility.get().getBaseFolder().child("settings.json");
try {
Reader reader = fileHandle.reader();
JsonObject json = Json.parse(reader).asObject();
reader.close();
for (Member member : json) {
Setting setting = settings.get(member.getName());
setting.readJson(member.getValue());
}
return true;
} catch (Exception e) {
Log.error("Failed to read settings", e);
fileHandle.delete();
return false;
}
}
示例3: Translator
import com.badlogic.gdx.files.FileHandle; //導入方法依賴的package包/類
public Translator(String language)
{
this.language = language;
translation = new HashMap<>();
// THIS FILE MUST BE UTF8 WITHOUT BOM
FileHandle file = Gdx.files.internal("translation/" + language + ".txt");
BufferedReader reader = new BufferedReader(file.reader("UTF8"));
ArrayList<String> lines = new ArrayList<>();
try
{
String line = reader.readLine();
while (line != null)
{
// 過濾掉註解#
if (!line.trim().equals("") && !line.trim().startsWith("#"))
{
lines.add(line.trim());
}
line = reader.readLine();
}
reader.close();
}
catch (IOException ioe)
{
}
// 檢查:翻譯ㄧ定要成對出現
if (lines.size() % 2 != 0)
{
Gdx.app.log("Translator", "ERROR READING FILE" + " translation/" + language + ".txt", new Exception("Lines of original texts and translated texts in the translation file do not match."));
}
for (int i = 0; i < lines.size(); i += 2)
{
String trans = lines.get(i + 1);
Gdx.app.log("Translator", lines.get(i).toLowerCase() + " => 加入翻譯 => " + trans + "\n");
translation.put(lines.get(i).toLowerCase(), trans);
}
}