Tech
Forums
Jobs
Books
Events
Videos
Live
More
Interviews
Certification
Training
Career
Members
News
Blogs
Contribute
An Article
A Blog
A Video
An Ebook
An Interview Question
Register
Login
1
Answer
Read column wise in csv file using java
Dinesh Santhalingam
7y
1k
1
Reply
I have a csv file.I want to read my csv file and store it in a seperate array using java.
ID
Name
1
ramesh
2
rani
3
rahane
4
raja
public static void main(String[] args) throws IOException {
ArrayList
<
String
>
ar
=
new
ArrayList
<
String
>
();
File
csvFile
=
new
File("C:\\Desktop\\r2.csv");
BufferedReader
br
=
new
BufferedReader(new FileReader(csvFile));
String
line
=
""
;
StringTokenizer
st
=
null
;
int
lineNumber
=
0
;
int
tokenNumber
=
0
;
while ((
line
=
br
.readLine()) != null) {
lineNumber++;
//use comma as token separator
st
=
new
StringTokenizer(line, ",");
while (st.hasMoreTokens()) {
tokenNumber++;
String
sd
=
st
.nextToken() + " ";
if(sd!=null){
ar.add(sd);
System.err.println(sd);
}
}
tokenNumber
=
0
;
}
}
In this Method all element stores in a single arraylist.
O/p:
ID
Name
1
ramesh
2
rani
3
rahane
4
raja
But my I want output like this:
o/p
ID Name
1 ramesh
2 rani
3 rahane
4 raja
two separate object.
help me to olve my issue.
Post
Reset
Cancel
Answers (
1
)
Next Recommended Forum
How to do this type of insert in 2d array in python?
I want to display the records frm DB on html page