java4all@1986 java. Powered by Blogger.

How to write read into CSV File?

>> Thursday, May 26, 2011

For example if we want create a csv file like
          Name   Place  Age
         bhas      VMR   23
         Aja        ONG   21





Here below code will explain easily how to to write the above data into CSV File
 
public class GenerateCsv1
{
    String name="bhaskar";
   

   private static void generateCsvFile(String sFileName)
   {
    try
    {
        FileWriter writer = new FileWriter(sFileName);

      
    writer.append("Name");
        writer.append(',');
writer.append("Place");
        writer.append(',');
        writer.append("Age");
        writer.append('\n');

        writer.append("Bhas");
        writer.append(',');
writer.append("Vmr");
        writer.append(',');
        writer.append("23");
            writer.append('\n');

        writer.append(""Aja);
        writer.append(',');
writer.append(""Ong);
        writer.append(',');
        writer.append("21");
        writer.append('\n');

        //generate whatever data you want

        writer.flush();
        writer.close();
    }
    catch(IOException e)
    {
         e.printStackTrace();
    }
    }
   public static void main(String [] args)
   { String csv="c://bhaskar.csv";
       GenerateCsv1.generateCsvFile(csv);
   }
}

      

0 comments:

Post a Comment

FaceBook Login

HTML/JAVASCRIPT

HTML/JAVASCRIPT

HTML/JAVASCRIPT

HTML/JAVASCRIPT

Total Pageviews

STATCOUNTER

  © Blogger template Simple n' Sweet by Ourblogtemplates.com 2009

Back to TOP