我有一个从文本文件中获取数据的程序。该文件格式,如Java - 丢失数据,包含字符串和整数的映射
Date/Time Tip From (Name)
Message(If one was left)
(Tipped Amount) (Total Tips Recieved)
我已经能够把我的代码,将其分离出来,并把它放在一个地图,使得它增加了所有每名并输出递减的方式提示。
E.g
INPUT ----------------------------------
Dec. 14, 2013, 2:31 a.m. Tip from rs
25 24986
Dec. 14, 2013, 2:27 a.m. Tip from ro
100 24961
Dec. 14, 2013, 2:27 a.m. Tip from rs
15 24861
Dec. 14, 2013, 2:25 a.m. Tip from da
3 24846
OUTPUT-----------------------------------
ro=100
rs=40
da=3
我现在碰到的问题。我发现我正在失去数据,不知道为什么。在文本文件中有1000个以上的文字,大约有2000行文字。其中一名学员,手工计算的X值为1990年。运行时,程序计算的实际计算值只比实际计算的少1690,300。我在试图调试时发现数据可能被删除或跳过的地方。
这里是从我的代码的摘录相关的计算器执行
while ((line = bufferedReader.readLine()) != null) {
if (line.contains("Tip from")) { // Finds the line that contains
// the tippers name
final String tipperName = line.substring(line
.indexOf("from ") + 5);
currentTipper = tipperName;
} else if (line.substring(0, 1).matches("\\d")) { // finds the
// line that
// contains
// the
// tipped
// amount
final Integer tipValue = Integer.parseInt(line.substring(0,
line.indexOf("\t")));
// here we store the tip in the map. If we have a record
// we
// sum, else
// we store as is
tipsByName
.put(currentTipper,
(tipsByName.get(currentTipper) == null ? 0
: tipsByName.get(currentTipper))
+ tipValue);
} else { // if line doesnt contain a name or a tip, skips to
// next line
bufferedReader.readLine();
}
}
如果完整的代码会更有帮助,请让我知道,我会编辑的帖子。
谢谢!
不要认为这是问题..但总是修剪()线。 – TheLostMind