TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Dinesh Santhalingam
NA
737
368.4k
Read column wise in csv file using java
Mar 29 2017 12:32 AM
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.
Reply
Answers (
1
)
How to do this type of insert in 2d array in python?
I want to display the records frm DB on html page