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 3 of 3

Thread: Extract data from a file

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

    Default Extract data from a file

    Hi All,
    Im trying to accomplish the following task and would like some advice.

    I have a file with some content I need to extract partial information that are found in a specific position. For instance in this file I have the following:

    //SOME DATA BEFORE THE POINT I WANT TO EXTRACT

    then at some point it starts the section where I want to get the data; it starts where it says !- === SHADING..etc

    !- =========== SHADING:ZONE: DETAILED ===========
    Shading:Zone: Detailed,
    Shading Device1,
    BUFFERSUD,
    ,
    4,
    0.2,
    -0.8,
    1.6,
    0.8,
    -0.8,
    2.8,
    0.8,
    -0.0,
    2.8,
    0.2,
    0.0,
    1.6;
    Shading:Zone: Detailed,
    Shading Device2,
    BUFFERSUD,
    ,
    4,
    0.8,
    -0.8,
    2.8,
    2.06,
    -0.81,
    2.96,
    2.0,
    -0.0,
    2.8,
    0.8,
    0.0,
    2.8;

    ..... etc. etc..

    Basically I want to store all numbers after the the 4. They are coordinates of some points. 12 altogether so 4 points. Most lilely I want to store them them in an array of length [3].
    My trouble are
    1) how do I start reading data from a specific point ? (basically after =========== SHADING:ZONE: DETAILED ===========)
    2) How do I fetch data so that I select in a sequence only the 12 points (exclduing so the first 5 rows)
    3) I need to repeat this until all sequence is ended. The sequence of the data I need to gather finish at a point where I have this string: !- =========== ALL OBJECTS IN CLASS: PEOPLE ===========)

    How would you approach this?


  2. #2
    Super Moderator Sean4u's Avatar
    Join Date
    Jul 2011
    Location
    Tavistock, UK
    Posts
    637
    Thanks
    5
    Thanked 103 Times in 93 Posts

    Default Re: Extract data from a file

    You'll have to read that file line-by-line until you detect the start of the lines you want to acquire, and then add them to your program data structure. The file looks like a sequential text file, so you can't really 'start reading' at any particular place, you'll have to go from the start.

  3. #3
    mmm.. coffee JavaPF's Avatar
    Join Date
    May 2008
    Location
    United Kingdom
    Posts
    3,336
    My Mood
    Mellow
    Thanks
    258
    Thanked 294 Times in 227 Posts
    Blog Entries
    4

    Default Re: Extract data from a file

    Might be worth looking at - http://www.javaprogrammingforums.com...ner-class.html
    Please use [highlight=Java] code [/highlight] tags when posting your code.
    Forum Tip: Add to peoples reputation by clicking the button on their useful posts.

Similar Threads

  1. Replies: 8
    Last Post: March 25th, 2011, 02:34 PM
  2. I want to extract minutes and seconds from duration
    By msa969 in forum What's Wrong With My Code?
    Replies: 1
    Last Post: March 17th, 2011, 02:14 PM
  3. How to extract text from web
    By HelloAll in forum Java Theory & Questions
    Replies: 4
    Last Post: January 10th, 2011, 05:50 AM
  4. Using File Data
    By computercoder in forum What's Wrong With My Code?
    Replies: 1
    Last Post: October 18th, 2010, 07:51 PM
  5. how to extract variables,keywords,operator...
    By Nanda in forum Java Theory & Questions
    Replies: 1
    Last Post: November 12th, 2009, 10:19 PM