我在一个文本文件中有一个事件日志,它每行有一个事件,包含空格并用空格分隔:
(a) the card number (16 digits, no spaces);
(b) the mode (B / T / F);
(c) item ON or OFF;
(d) the zone number; and
(e) the time in milliseconds since the epoch.
Example:
1234123412340001 B ON 3 1377222203257
1234123412340007 T ON 1 1377222238204
1234123412340003 F OFF 5 1377222275153
我需要创建一个程序来读取标准输入中的所有事件并将它们再次打印到标准输出
示例输出:
$ java TestEvent < event-log.txt
1234123412340001 B ON 3 1377222203257
1234123412340007 T ON 1 1377222238204
1234123412340003 F OFF 5 1377222275153
$
这是我到目前为止所拥有的:
public Event(String cardNumber, int mode, boolean on, int zone, long time) {
private String cardNumber;
private int mode;
private boolean on;
private int zone;
private long time;
}
Scanner = new Scanner(new FileInputStream(args[0]));
public void TestEvent()
{
Scanner sc = IOHelper.createScanner(("args[0])");
while (in.hasNextLine()) // NOT at the end of the stream, more input is available
{
String thisLine = sc.nextLine(); // Get an entire line
for (int index=0; index < thisLine.length(); index++)
{
char ch = thisLine.charAt(index);
System.out.print(ch);
}
System.out.println();
}
in.close();
}
我的Java知识很差,但基本上我在问如何从文件中提取数据并检查所有数据是否存在(验证它是否存在)并再次打印出来?
*完全披露:这不适用于任何家庭作业。只是为了我自己的知识。