aspose file tools*
The moose likes Beginning Java and the fly likes Need your's Help Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Need your Watch "Need your New topic
Author

Need your's Help

Mohammed Riaz
Greenhorn

Joined: Nov 15, 2006
Posts: 17
I need to create comma separted values file (i.e) *.csv file in java. I want to write values from ArrayList to *.csv file(by creating new file).


If any have code relevant to this. please send to riaz.engg@gmail.com

or post over here.

It is urgent!! Please !!!


Thanks & Regards...<br />Riaz<br />SCJP1.4<br />SCWCD(preparing)
Subhadip Chatterjee
Ranch Hand

Joined: Dec 12, 2006
Posts: 93
Hi Bro,
you have to mention, exactly in which way you wanna see the records in the CSV file. Otherwise if it's a simply ArrayList to CSV file conversion then,follow the simple program below (Still i think, you might have some special requirements, that's what you have to mention specifically):

import java.io.*;
import java.util.ArrayList;

public class CSVWriter{
private static BufferedWriter writeInto = null;
private static File newFile = null;
public static void main(String args[]){
ArrayList holdValues = new ArrayList();
holdValues.add("10");
holdValues.add("20");
holdValues.add("30");
holdValues.add("40");
holdValues.add("50");
holdValues.add("60");
try{
newFile = new File("d:\\Test\\try.csv");
writeInto = new BufferedWriter(new FileWriter(newFile));
for(int index=0;index<holdValues.size();index++){
String temp = (String)holdValues.get(index);
writeInto.write(temp,0,temp.length());
if(index != holdValues.size()-1){
writeInto.write(',');
}
}
}
catch(IOException ex){
System.out.println("Exception in File operation:"+ex);
}
finally{
try{
writeInto.flush();
writeInto.close();
}
catch(IOException exc){
exc.printStackTrace();
}
}
}
}
[ January 11, 2007: Message edited by: Subhadip Chatterjee ]

Refreshing life every moment...
Mohammed Riaz
Greenhorn

Joined: Nov 15, 2006
Posts: 17
Thanks Brother,

For one Row it is working perfectly and but with multiple rows coming
from data base, i need to insert one row in one line and next row in another line..

Do you have any code for this?

Any way thanks boss....
Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336

Not and advanced question. Moving...


JavaRanch FAQ HowToAskQuestionsOnJavaRanch
Stan James
(instanceof Sidekick)
Ranch Hand

Joined: Jan 29, 2003
Posts: 8791
Look through the JavaDoc for that BufferedWriter. See if you find a way to make a new line.


A good question is never answered. It is not a bolt to be tightened into place but a seed to be planted and to bear more seed toward the hope of greening the landscape of the idea. John Ciardi
Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 14432
    
  23

Topic: Need your's Help

When you ask a question, please use a meaningful subject line. What would the forum look like if all topics had the title "please help", "need your help", etc.?

I need to create comma separted values file (i.e) *.csv file in java. I want to write values from ArrayList to *.csv file(by creating new file).

Please search first. You'll find a lot of answers very quickly if you search for "java csv" - you're not the first person who's trying to do something with CSV in Java.

If any have code relevant to this. please send to riaz.engg@gmail.com

Please use the forum, not e-mail.

It is urgent!! Please !!!

Please, ease up.

Please read How to Ask Questions on JavaRanch.


Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 8 API documentation
Mohammed Riaz
Greenhorn

Joined: Nov 15, 2006
Posts: 17
ok man... cool.. sorry for my post without studying those things..
David McCombs
Ranch Hand

Joined: Oct 17, 2006
Posts: 212
Originally posted by Mohammed Riaz:

Do you have any code for this?



No, what is the purpose of having code handed to you? If you want to learn, write some code and ask questions along the way!


"Should array indices start at 0 or 1? My compromise of 0.5 was rejected without, I thought, proper consideration."- Stan Kelly-Bootle
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Need your's Help