Results 1 to 6 of 6
  1. #1
    phani532 is offline Member
    Join Date
    Aug 2008
    Posts
    1
    Rep Power
    0

    Thumbs down Adding lines at start and end of the text file

    Hi I need to add a few lines to existing text file how could i do it..
    Example
    if a.txt contains

    SELECT VERSION FROM PSVERSION WHERE OBJECTTYPENAME = 'SYS' ;
    SELECT STYLESHEETNAME FROM PSOPTIONS;
    SELECT VERSION FROM PSVERSION WHERE OBJECTTYPENAME = 'SYS' ;
    SELECT STYLESHEETNAME FROM PSOPTIONS;

    I need to add create procedure in the first line and end procedure in last line.....
    Output must be.
    CREATE OR REPLACE PROCEDURE
    BEGIN
    SELECT VERSION FROM PSVERSION WHERE OBJECTTYPENAME = 'SYS' ;
    SELECT STYLESHEETNAME FROM PSOPTIONS;
    SELECT VERSION FROM PSVERSION WHERE OBJECTTYPENAME = 'SYS' ;
    SELECT STYLESHEETNAME FROM PSOPTIONS;
    END PROCEDURE
    /
    Can you suggest me any method

  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

    Read the file into a StringBuffer. Append additional lines to correct places, and write back to a file that new StringBuffer.

  3. #3
    jsemmanuel is offline Member
    Join Date
    Aug 2008
    Posts
    3
    Rep Power
    0

    Default

    say the file is quite large, wouldn't it be better to create a temp file with the new text, append original stuff to it, delete original fie and rename temp?

  4. #4
    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

    Ya, it's not bad though. Only the point you have to consider is how to read the file content. What ever to do first you have to read the file. In a StringBuffer you can hold larger data, unless you didn't comes with a memory issue in the system.

  5. #5
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,514
    Rep Power
    25

    Default

    What ever to do first you have to read the file.
    But you don't have to keep all of it in memory. You would only need to keep one record at a time. The previously read records would be written out to the new file and the records to be read in the future would still be on disk.

  6. #6
    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

    Yes Norm, I'm trying to explain the same. Actually we have to read one record at a time, and depend on the implementing we can achieve in different ways. That's why I pointed about the memory issue, if read the large data. For a simple record file it doesn't matter.

Similar Threads

  1. [SOLVED] Writing ArrayList to Text File on seperate Lines
    By shinjitsunohana in forum New To Java
    Replies: 9
    Last Post: 08-27-2008, 05:53 PM
  2. Adding a new class to a jar file
    By Raul Menendez in forum New To Java
    Replies: 2
    Last Post: 08-21-2008, 04:52 PM
  3. Remove duplicate lines from a text file
    By Dirt.Diver in forum New To Java
    Replies: 15
    Last Post: 06-25-2008, 02:08 PM
  4. Replies: 0
    Last Post: 04-06-2008, 07:45 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
  •