|
こんなんでえぇのかの。
--- foo.java ---
import java.io.*;
import java.util.*;
class Student {
public int studentNum;
public String name;
public String hobby;
static Student fromCSV(String line) {
StringTokenizer tokenizer = new StringTokenizer(line,",");
Student result = new Student();
result.studentNum = Integer.parseInt(tokenizer.nextToken());
result.name = tokenizer.nextToken();
result.hobby = tokenizer.nextToken();
return result;
}
}
public class foo {
static ArrayList<Student> readCSV(String path) throws Exception {
ArrayList<Student> result = new ArrayList<Student>();
BufferedReader reader = new BufferedReader(new FileReader(path));
while ( reader.ready() ) {
result.add(Student.fromCSV(reader.readLine()));
}
reader.close();
return result;
}
public static void main(String[] args) {
try {
for ( Student s : readCSV(args[0]) ) {
System.out.printf("#%d: %s (%s)\n", s.studentNum, s.name, s.hobby);
}
} catch (Exception ex) {
ex.printStackTrace();
}
}
}
--- foo.csv ---
1,episteme,C++
2,naka,C#
3,janne,VB
4,hatsune,Oracle
5,nagise,Java
--- java foo foo.csv ---
#1: episteme (C++)
#2: naka (C#)
#3: janne (VB)
#4: hatsune (Oracle)
#5: nagise (Java)
|