Saturday, 29 September 2018

Java program to WRITE A CSV FILE

import java.io.File;
import java.io.FileNotFoundException;
import java.io.PrintWriter;


public class CSVwrite {
    public static void main(String[]args) throws FileNotFoundException{
        PrintWriter pw = new PrintWriter(new File("abc.csv"));
        StringBuilder sb = new StringBuilder();
        sb.append("id");
        sb.append(',');
        sb.append("Name");
        sb.append('\n');

        sb.append("1");
        sb.append(',');
        sb.append("sateesh bagadhi");
        sb.append('\n');

        pw.write(sb.toString());
        pw.close();
        System.out.println("done!");
    }
}


No comments: