0

我在一个文本文件中有一个事件日志,它每行有一个事件,包含空格并用空格分隔:

(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知识很差,但基本上我在问如何从文件中提取数据并检查所有数据是否存在(验证它是否存在)并再次打印出来?

*完全披露:这不适用于任何家庭作业。只是为了我自己的知识。

4

1 回答 1

0

您可以使用 FileInputStreamReader,使其成为对象,然后使用 readLine 方法简单地读取行格式文件。

当您从文件中获取数据时,然后将其与您的要求进行比较。

整个事情都放在while循环中,就是这样。

于 2013-08-27T14:38:24.457 回答