【发布时间】:2015-12-23 09:05:15
【问题描述】:
我是 Java 新手。我正在尝试在文本文件上做一个数据库(不要问我为什么)。我想做的是读取文本文件的特定行。
文本文件:
Salary
3,400
21/12/2015
Tax Refund
3
22/12/2015
Tax Refund
320
23/12/2015
Savings Deposit
1,230
23/12/2015
Bonus
343
23/12/2015
每 3 行就有一个新条目。例如,Salary 是类别,3,400 是金额,21/12/2015 是日期。我想做的是只读取金额(例如 3,400 3 320 1,230 等)。我唯一成功做的就是通过在真正的打印语句上匹配它们来打印行,使用以下代码:
while(opnEsoda.hasNext()) { // diabazei kathe seira sto txt
// diabazei kathe seira kai emfanizei to value tis kathe mias ana 3.
System.out.print("You got money from: " + opnEsoda.nextLine()+ ", ");
System.out.print("Amount: " + opnEsoda.nextLine()+", ");
System.out.print("Date: " + opnEsoda.nextLine()+". ");
System.out.println();
}
opnEsoda 是扫描仪并打印:
You got money from: Salary, Amount: 3,400, Date: 21/12/2015.
You got money from: Tax Refund, Amount: 3, Date: 22/12/2015.
You got money from: Tax Refund, Amount: 320, Date: 23/12/2015.
You got money from: Savings Deposit, Amount: 1,230, Date: 23/12/2015.
You got money from: Bonus, Amount: 343, Date: 23/12/2015.
【问题讨论】:
-
问题是什么?
-
@sidgate 我需要做什么才能只打印金额? (例如 3,400 3 320 1,230 等)。
标签: java java.util.scanner file-handling file-read