Results 1 to 4 of 4
  1. #1
    prabhurangan is offline Member
    Join Date
    May 2008
    Posts
    69
    Rep Power
    0

    Default Java file reader...?

    Hi Members,

    I have to read a file and append to string. In this i have to check for my start and end 'Delimiter'. and the data read from file should be appended to a first string until the 'start' delimiter is found, once the start delimiter is found, the remaining part of the file, upto the 'end delimiter' should be appended to another string.

    Example: File.txt
    "This is a sample file for your information. JESUS Please help me in this , this logic code should be done in java. MARY I tried using String.split() function but i could not get the solution."

    This is the content of the file. Here im setting my 'start delimiter' as 'JESUS' and 'end delimiter' as 'MARY' and until the start delimiter is found i should read the data from file and append it to first string and once after the first delimiter is found and until the end delimiter is found i have to append it to another string.

    So, the output should be :

    String firstData = "This is a sample file for your information. I tried using String.split() function but i could not get the solution.";
    String secondData = "Please help me in this , this logic code should be done in java. ";

    Looking forward for the logic code done in Java.


    Regards,
    Prabhu.

  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
    19

    Default

    Is that file contain those text as a paragraph or as a collections of lines?

    One of the simple way I can see is, read a line and split/tokernize into words based on the space character. So the result you have is in an array. Once you found the delimiters store the result in another array and retrieve a string from there, and do the process.

  3. #3
    prabhurangan is offline Member
    Join Date
    May 2008
    Posts
    69
    Rep Power
    0

    Default Java file reader ..?

    Eranga,

    This is a collection of lines. FYI. This is a backup *.sql file, I have to read the file and store it to a string and once my start delimiter is found and upto the end delimiter i define it should save it to another string.


    Prabhu.

  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
    19

    Default

    If you have a collection of lines, it's much easier. As I said read a line-by-line and split in into words based on the space character. Then validate each word for your delimiter.

    Did you try anything so far?

Similar Threads

  1. [SOLVED] Need help with file reader
    By syed.shuvo in forum New To Java
    Replies: 6
    Last Post: 09-27-2008, 07:43 PM
  2. FileReader / Buffered Reader
    By sepaht in forum New To Java
    Replies: 9
    Last Post: 07-10-2008, 08:05 PM
  3. [SOLVED] reader and writer on same file handle
    By Nicholas Jordan in forum Advanced Java
    Replies: 11
    Last Post: 07-01-2008, 03:39 AM
  4. A simple DOM reader
    By Java Tip in forum Java Tip
    Replies: 0
    Last Post: 01-03-2008, 09:24 AM
  5. help with file reader
    By jason27131 in forum New To Java
    Replies: 1
    Last Post: 08-01-2007, 03:03 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
  •