开发者

Java: Syntax problem

I want 开发者_如何学JAVAto use the above code for one more argument, sayargs[2]. Where should I make changes? Will nextline remain the same or does it become nextline[1]?


Assuming args[2] holds the name of your second data input file, then you'll have to create a second reader for that file. A quick solution with a simple for loop, skipping exception handling:

for (int i = 1; i <= 2; i++){
  CSVReader reader = new CSVReader(new FileReader(args[i]));
  String [] nextLine;
  while ((nextLine = reader.readNext()) != null) {
         // nextLine[] is an array of values from the line
         //System.out.println(nextLine[0] + nextLine[1] + "etc...");

         for (String value:nextLine)
           System.out.print(value+" ");
         System.out.println();
  }
  reader.close();
}

The number of values in a line can be determined with nextLine.length.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜