【发布时间】:2018-03-18 16:36:04
【问题描述】:
我正在编写一个简单的程序来跟踪我的油耗。我想弄清楚为什么换行符没有输出 到文件,但其他字段是。
PrintWriter fuelLog = new PrintWriter(new FileWriter("FuelLog.txt", true));
fuelLog.println("New Trip");
miles = JOptionPane.showInputDialog("Please enter trip miles...");
dollars = JOptionPane.showInputDialog("Please enter cost to refuel...");
gallons = JOptionPane.showInputDialog("Enter the gallons used on the trip...");
fuelLog.println("Miles on trip: " + miles + "\n" +
"Cost: $" + dollars + "\n" +
"Gallons used: " + gallons);
fuelLog.close();
我的文件的输出最终是这样的,例如:
旅行里程:270.67 成本:33.76 美元使用加仑:11.567
我要查找的文件的所需输出是:
行程里程:270.67
成本:33.76 美元
使用加仑数:11.567
【问题讨论】:
标签: java eclipse newline filewriter