我在尋找一些關於如何讀取具有特定格式的文本文件的幫助,並將它們分配給我的程序中的變量。讀取具有特定格式的文本文件
TextFile.txt的
//Variables
start={x}
forward={c}
end={y}
pause={p}
path={x, c, c, c, c, p, c, c, y}
Class.java
public void readFile()
{
char start, forward, end, pause;
BufferedReader reader =
new BufferedReader (
new InputStreamReader (new FileInputStream (TextFile.txt)));
String line;
while ((line = reader.readLine()) != null)
{
if (line.startWith ("//") || line.trim().isEmpty())
continue; // Ignore the line
//**This is the part I need help with**
}
}
可能有人請解釋:我可以分配值,從文本文件中的變量?
因此,例如,開始將等於 'X',正向應該是 'C' 等
感謝。
在上面的例子中,'path'是一個數組嗎? –
路徑將是一個鏈接列表,每個節點都是一個字符。 – GuestUser140561
這些是文件中唯一的變量嗎?關於後退,左側,右側等等? –