Results 1 to 10 of 10
  1. #1
    trkece is offline Member
    Join Date
    Feb 2011
    Posts
    22
    Rep Power
    0

    Default How to write column by column to text file

    Hi all

    I want to write the data into text file column by column

    NAme, MArks, SEx
    Rama, 95, M
    Sri, 85. F

    I am getting the output as
    Name
    Rama
    Sri
    MArks
    95
    85
    Sex
    M
    F

    Can any one tell me the way...........

  2. #2
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    20

    Default

    Since you are writing the content to a text file, you can do something like this.

    Calculate the number of rows initially. Once the first column is written into the text file, move to next column and to beginning of the text file. Then read the each line and append the new stuff to is and write back to file.

    But my advice is not to do this really. Reason is that process is bulky. Best way is to write the entire line at the same time.

    I hope you retrieve data from a database, and the content in a DataTable. So it's easy to deals with line-by-line.

  3. #3
    trkece is offline Member
    Join Date
    Feb 2011
    Posts
    22
    Rep Power
    0

    Default

    Thanx for the reply,
    but I don't want some columns from that table, i want to select only some columns and write it to the new file,

    can u pls tell me how to move to next column and beginning of the file ??

    Pls help me out ......

  4. #4
    trkece is offline Member
    Join Date
    Feb 2011
    Posts
    22
    Rep Power
    0

    Default

    can u pls help me out.................

  5. #5
    trkece is offline Member
    Join Date
    Feb 2011
    Posts
    22
    Rep Power
    0

    Default

    I need to write particular excel columns to one notepad for my applicarion

    so i need to column wise write to tat text file....... pls help me out

  6. #6
    gcalvin is offline Senior Member
    Join Date
    Mar 2010
    Posts
    953
    Rep Power
    5

    Default

    Quote Originally Posted by trkece View Post
    Hi all

    I want to write the data into text file column by column

    NAme, MArks, SEx
    Rama, 95, M
    Sri, 85. F

    I am getting the output as
    Name
    Rama
    Sri
    MArks
    95
    85
    Sex
    M
    F

    Can any one tell me the way...........
    The short answer is that you can't write to a text file column-by-column. Text files just don't work like that. So if you want to create a text file like that, you need to compose it one line at a time.

    Write a sample out on paper, thinking about what you are doing step-by-step. Then come back and tell us what all the steps are, and we can help you turn that into Java code.

    -Gary-

  7. #7
    trkece is offline Member
    Join Date
    Feb 2011
    Posts
    22
    Rep Power
    0

    Default

    EmpId Name Designation Order
    1 ABC Software Engineer 7/8/2010
    2 DFG Sr Software Engineer 7/15/2010
    3 LOI Team Leader 9/1/2010
    4 LKJ Project Manager 9/1/2010
    5 QWE Software Architect 8/23/2010
    This is in Excel, I want Name and Order columns in csv file with some delimiter like dis

    Name, Order
    ABC,7/8/2010
    DFG,7/15/2010
    LOI,9/1/2010
    LKJ,9/1/2010
    QWE,8/23/2010

    for me i am getting output in the same colum like dis

    Name
    ABC
    DFG
    LOI
    LKJ
    QWE
    Order
    7/8/2010
    7/15/2010
    9/1/2010
    9/1/2010
    8/23/2010


    Pls help me out..........

  8. #8
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    20

    Default

    Quote Originally Posted by trkece View Post
    Thanx for the reply,
    but I don't want some columns from that table, i want to select only some columns and write it to the new file,

    can u pls tell me how to move to next column and beginning of the file ??

    Pls help me out ......
    Sorry for the late reply.

    So if you want to filter only few columns, rather using "SELECT * ... " specify all columns you want and filter.

  9. #9
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    20

    Default

    Quote Originally Posted by trkece View Post
    This is in Excel, I want Name and Order columns in csv file with some delimiter like dis
    How did you read the excel file. You have to query it. As I told you in my previous post change the query appropriately first of all. Then you can create the line at the same time, that you want to write into text file.

  10. #10
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    20

    Default

    Quote Originally Posted by gcalvin View Post
    Write a sample out on paper, thinking about what you are doing step-by-step. Then come back and tell us what all the steps are, and we can help you turn that into Java code.

    -Gary-
    That's pretty good Gary. I feel too that OP doesn't tryout anything yet. :)

Similar Threads

  1. insert row and column and delete row and column
    By daredavil82 in forum New To Java
    Replies: 13
    Last Post: 09-22-2011, 06:10 PM
  2. Replies: 4
    Last Post: 02-05-2011, 06:47 PM
  3. Reading CSV file with miltiline column
    By dekha in forum Advanced Java
    Replies: 8
    Last Post: 12-13-2010, 09:23 AM
  4. Add new column to csv file
    By Tota in forum New To Java
    Replies: 0
    Last Post: 08-31-2010, 03:32 PM
  5. Replies: 1
    Last Post: 07-06-2010, 04:50 PM

Posting Permissions

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