我正在尝试读取一个包含以下内容的简单文本文件:
加载
比尔豆
1200
20
15
30
放弃
我需要逐行存储和打印内容。 我正在使用以下代码:
String inputFile = "(file path here)";
try {
Scanner input = new Scanner(inputFile);
} catch (FileNotFoundException e) {
e.printStackTrace();
}
String currentLine = "";
while (!currentLine.equals("QUIT}")){
currentLine = input.nextLine();
System.out.println(currentLine);
}
input.close();
但是,输出非常“混乱”。 我试图避免存储所有换行符以及文本文件中未出现的其他任何内容。 输出为:
{\\ rtf1 \\ ansi \\ ansicpg1252 \\ cocoartf949 \\ cocoasubrtf540
{\\ fonttbl \\ f0 \\ fmodern \\ fcharset0 Courier;}
{\\ colortbl; \\ red255 \\ green255 \\ blue255;}
\\ margl1440 \\ margr1440 \\ vieww9000 \\ viewh8400 \\ viewkind0
\\ deftab720
\\ pard \\ pardeftab720 \\ ql \\ qnatural
\\ f0 \\ fs26 \\ cf0加载\\
比尔的豆\\
1200 \\
20 \\
15 \\
30 \\
放弃}
任何帮助将不胜感激,谢谢!