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
.
精彩评论