instanceof java
Posts: 576
Nickname: instanceof
Registered: Jan, 2015
instanceof java is a java related one.
How to create csv file in java using filewriter
Posted: Aug 17, 2016 10:19 AM
This post originated from an RSS feed registered with Java Buzz
by instanceof java.
Original Post: How to create csv file in java using filewriter
Feed Title: Instance Of Java
Feed URL: http://feeds.feedburner.com/blogspot/TXghwE
Feed Description: Instance of Java. A place where you can learn java in simple way each and every topic covered with many points and sample programs.
Latest Java Buzz Posts
Latest Java Buzz Posts by instanceof java
Latest Posts From Instance Of Java
Advertisement
We can create CSV file and fill some data in to it using java program. We can create CSV file and write data int to CSV file using java.io.FileWriter class. Creating object of java.io.FileWriter class by giving output filename. After creating object of java.io.FileWriter append data by calling append("data") method of FileWriter class object. Use append('\n'); for enter data in new row. Lets see a java example program on how to create csv file and write data in to it using FileWriter Class.
Program #1: Java program to create CSV file using FileWriter class package com.java.createcsvfile; import java.io.FileWriter; import java.io.IOException; public class CreateCsvFile { private static void generateCsvFile(String fileName) { FileWriter writer = null; try { writer = new FileWriter(fileName); writer.append("Name"); writer.append(','); writer.append("Number"); writer.append('\n'); writer.append("interview questions"); writer.append(','); writer.append("001"); writer.append('\n'); writer.append("interview programs"); writer.append(','); writer.append("002"); writer.append('\n'); System.out.println("CSV file is created..."); } catch (IOException e) { e.printStackTrace(); } finally { try { writer.flush(); writer.close(); } catch (IOException e) { e.printStackTrace();} } } public static void main(String[] args) { String location = "E:\\newCsvFile.csv"; generateCsvFile(location);} } Output:
Read: How to create csv file in java using filewriter