0
我读一个CSV文件看起来像以下:阅读CSV文件,标题和多个列
Red Blue Green
1st Y N
2nd Y Y N
3rd N Y
我所要的输出是这样的
1红Ÿ
1蓝ñ
第二红色Ÿ
第二蓝色Y
第二届绿色ň
3红ñ
3rd Green Y
我将颜色行拉入数组中,但我不知道如何获得所需的输出。下面是我到目前为止的代码:
public String readFile(File aFile) throws IOException {
StringBuilder contents = new StringBuilder();
ArrayList<String> topRow = new ArrayList<String>();
try {
BufferedReader input = new BufferedReader(new FileReader(aFile));
try {
String line = null;
while ((line = input.readLine()) != null){
if(line.startsWith(",")) {
for (String retval: line.split(",")) {
topRow.add(retval);
//System.out.println(retval);
}
}
}
}
finally {
input.close();
}
}
catch (IOException ex){
ex.printStackTrace();
}
return contents.toString();
}
不要重新发明轮子。使用现有的***调试过的*** CSV库(有几个)。 –