File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Need your's Help

 
Mohammed Riaz
Greenhorn
Posts: 17
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 !!!
 
Subhadip Chatterjee
Ranch Hand
Posts: 93
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
Mohammed Riaz
Greenhorn
Posts: 17
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 10336
Eclipse IDE Hibernate Java
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Not and advanced question. Moving...
 
Stan James
(instanceof Sidekick)
Ranch Hand
Posts: 8791
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Look through the JavaDoc for that BufferedWriter. See if you find a way to make a new line.
 
Jesper de Jong
Java Cowboy
Saloon Keeper
Pie
Posts: 15150
31
Android IntelliJ IDE Java Scala Spring
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Mohammed Riaz
Greenhorn
Posts: 17
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ok man... cool.. sorry for my post without studying those things..
 
David McCombs
Ranch Hand
Posts: 212
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic