Results 1 to 6 of 6
  1. #1
    papele is offline Member
    Join Date
    Jan 2010
    Posts
    3
    Rep Power
    0

    Default expoprt date to csv file

    Hi all, I've a problem with a simple java code. I've to export String in csv file. I've done this right but I could not move the text into columns, only rows.
    How can I move the text into columns?

    This is my code:
    Java Code:
    import java.io.FileWriter;
    import java.io.IOException;
     
    public class GenerateCsv
    {
       public static void main(String [] args)
       {
    	   generateCsvFile("test.csv"); 
       }
     
       private static void generateCsvFile(String sFileName)
    	{
    		try
    		{
    		    
    		    FileWriter writer = new FileWriter(sFileName);
    		    
    			writer.append("DisplayName");
    			writer.append(',');
    			writer.append("Age");
    			writer.append('\n');
    			
     
    			writer.append("MKYONG");
    			writer.append(',');
    			writer.append("26");
    			writer.append('\n');
    			
    			writer.append("YOUR NAME");
    			writer.append(',');
    			writer.append("29");
    			writer.append('\n');
     
    			//generate whatever data you want
     
    			writer.flush();
    			writer.close();
    		}
    		catch(IOException e)
    		{
    		 e.printStackTrace();
    		} 
    	}
    }
    For example,
    Java Code:
     writer.append('\n');
    down one line but I want to move in the next column right (of csv file), not down line.

    Thank you all :)

  2. #2
    dlorde is offline Senior Member
    Join Date
    Jun 2008
    Posts
    339
    Rep Power
    7

    Default

    :confused: In CSV files, the 'columns' are separated by commas (,) - hence the name Comma Separated Value (CSV).

  3. #3
    papele is offline Member
    Join Date
    Jan 2010
    Posts
    3
    Rep Power
    0

    Default

    Hi dlorde,
    I know that In CSV files, the 'columns' are separated by commas (,) but, as you can see from my code, I use
    Java Code:
     writer.append(',');
    but it dosen't work correctly.

    I don't understand if you meant this.

    Could you write the instruction to move in the right column?

    Thank you

    :)

  4. #4
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,014
    Rep Power
    20

    Default

    So, what output do you get?
    Because that looks correct to me.

  5. #5
    papele is offline Member
    Join Date
    Jan 2010
    Posts
    3
    Rep Power
    0

    Default

    This is my output on csv file now:


    This is the output I want:



    Thank you :)
    Last edited by papele; 01-28-2010 at 12:52 PM.

  6. #6
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,014
    Rep Power
    20

    Default

    No it isn't.
    That's your output as viewed through whatever spreadhseet program you're using.
    What does the csv file look like in a text editor, because to me it looks like the csv is fine, but your spreadsheet program isn't.

    In any case, the output you want is not what would normally be thought of as the layout for a csv as seen through a spreadsheet.

Similar Threads

  1. How to print the creation date of a jar file
    By lunarbof in forum Advanced Java
    Replies: 9
    Last Post: 08-22-2008, 06:12 PM
  2. Replies: 0
    Last Post: 04-05-2008, 10:10 AM
  3. How to find file created date.....
    By roshithmca in forum Advanced Java
    Replies: 1
    Last Post: 02-18-2008, 09:48 AM
  4. File creating date/time
    By bugger in forum New To Java
    Replies: 1
    Last Post: 11-11-2007, 07:43 PM
  5. Date format display in CSV file after exporting
    By latha in forum Advanced Java
    Replies: 0
    Last Post: 08-03-2007, 08:09 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •