• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Bear Bibeault
  • Junilu Lacar
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • salvin francis
  • Frits Walraven
Bartenders:
  • Scott Selikoff
  • Piet Souris
  • Carey Brown

Need your's Help

 
Greenhorn
Posts: 17
  • 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 !!!
 
Ranch Hand
Posts: 93
  • 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
  • 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....
 
Bartender
Posts: 10336
Hibernate Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Not and advanced question. Moving...
 
(instanceof Sidekick)
Posts: 8791
  • 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.
 
Java Cowboy
Posts: 16084
88
Android Scala IntelliJ IDE Spring Java
  • 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
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ok man... cool.. sorry for my post without studying those things..
 
Ranch Hand
Posts: 212
  • 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!
 
There were millions of the little blood suckers. But thanks to this tiny ad, I wasn't bitten once.
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
    Bookmark Topic Watch Topic
  • New Topic