I need to parse a csv file and store the data into a java bean class. Like:
email,fname,lname
[email protected],abc,xyz
These details into a bean class. I am able to parse a csv file. How to store details in bean class.
private static List<List<String>> readTXTFile(String csvFileName) throws IOException {
String line = null;
BufferedReader stream = null;
List<List<String>> csvData = new ArrayList<List<String>>();
try {
stream = new BufferedReader(new FileReader(csvFileName));
while ((line = stream.readLine()) != null) {
String[] splitted = line.split(",");
List<String> dataLine = new ArrayList<String>(splitted.length);
for (String data : splitted)
dataLine.add(data);
csvData.add(dataLine);
}
} finally {
if (stream != null)
stream.close();
}
return csvData;
}
the above code is parsing csv file but i want that data to be inserted in java bean class.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…