Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 2 of 2

Thread: Writing formatted data to file

  1. #1
    Junior Member
    Join Date
    Jun 2011
    Posts
    14
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default Writing formatted data to file

    Hi All,

    I am writing to have your advise on how to approach this task. I am quite new to Java and programming hence I ask help.
    I need to write a file based on comma separated field where each line is defined by a semicolon. Most of the values in this file are constant i.e. there some fixed information that can be already stored in it. Other information need to be edited/added and will be variables.

    For instance if you look at the attached txt it gives you an idea how the file I want to write need to be. ! or / Are comments and not processed. In this file fields are grouped in classes and every class has a constant name for instance if you go to line 668 Lights is the class of the objects described in that section. All fields of the class can be assigned by variables. Luckly there some information that will never change in my case so I need to edit just few yet important values.

    In particular I ll need to edit some data from line 611 - this data is formatted like this:

    Shading:Zone:Detailed,
    Shading Device1, !- Name
    Daylit South Wall, !- Base Surface Name
    , !- Transmittance Schedule Name
    4, !- Number of Vertices
    0, !- Vertex 1 X-coordinate {m}
    0, !- Vertex 1 Y-coordinate {m}
    20, !- Vertex 1 Z-coordinate {m}
    0, !- Vertex 2 X-coordinate {m}
    -1.5, !- Vertex 2 Y-coordinate {m}
    20, !- Vertex 2 Z-coordinate {m}
    5, !- Vertex 3 X-coordinate {m}
    -1.5, !- Vertex 3 Y-coordinate {m}
    20, !- Vertex 3 Z-coordinate {m}
    5, !- Vertex 4 X-coordinate {m}
    0, !- Vertex 4 Y-coordinate {m}
    20; !- Vertex 4 Z-coordinate {m}

    so every field of this object is a variable that will passed from my program and written in this file. My question are:
    - how do you would you approach this task and how would you organize data to be referenced?
    - how do you write in a specific location in a file where there already some information stored? is it possible?

    Thanks
    Attached Files Attached Files


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: Writing formatted data to file

    how do you write in a specific location in a file where there already some information stored? is it possible?
    You can write to specific locations in a RandomAccessFile. The new data will replace what was there before.
    To be able to do this, all the records and fields must be of fixed length. If the new is shorter than the old, the extra old will remain in the file. If the new is longer than the old, it will overlay some data in the beginning of the next record.

Similar Threads

  1. displaying dyanamic data on jsp while core engine is writing it on text file
    By abhyudayaupadhyay in forum File I/O & Other I/O Streams
    Replies: 5
    Last Post: May 24th, 2011, 10:03 AM
  2. file reading & writing
    By macko in forum What's Wrong With My Code?
    Replies: 7
    Last Post: May 12th, 2011, 08:54 AM
  3. Replies: 1
    Last Post: April 7th, 2011, 01:32 PM
  4. Replies: 8
    Last Post: March 25th, 2011, 02:34 PM
  5. Writing data to the java DefaultTableModel
    By dubois.ford in forum What's Wrong With My Code?
    Replies: 1
    Last Post: April 1st, 2010, 08:43 PM

Tags for this Thread