Hi,
I m trying to write code to merge two csv files. could any one help me out to get the hints to start?

Recommended Answers

All 6 Replies

Not enough info. Merge by concatenation, by joining records in input order, by joining based on a key value present in both files? Etc?
Formats or examples of both files, and how are they to be merged (or an example output file) would be really helpful here.

I'm sorry for that.
Here are the example files,
1st file looks like:
sno,first name,last name
1,xx,yy
2,aa,bb

2nd file looks like:
sno,place
1,pp
2,qq

Output:
sno,first name,last name,place
1,xx,yy,pp
2,aa,bb,qq

OK, no problemo.
Are you looking for a quick'n'dirty way or a good Java object-oriented way?

for time being I need a quick way

Read each file into a map (2 files, 2 maps) by extracting the sno to use as key, and put the rest of the line as the value.
When you have the two maps look through all the keys in the first map, and get the corresponding values from both maps. For each key concatenate the key with both values and write that to the output file.

I'm sorry, I m very beginner. Could u explain more plz :-(

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.