Results 1 to 3 of 3
  1. #1
    M0RT is offline Member
    Join Date
    Feb 2012
    Posts
    2
    Rep Power
    0

    Default Getting specific values from a file

    Hello guys,
    New to java and I'm already stuck. My issue is the following: I have a file I need to get specific values from and I don't really know how to get to that specific line and get the values needed. The values I want are all the numbers in between the curly brackets {} on the lines that start with either "t" or "c" and the last line. I want to store the values in an array so I can later do mathematical operations with them.
    The file looks like this:

    p "Defender's choice" 1 1 "" { "Patch and IDS" "Patch" "IDS" "None" } 0
    p "Attacker's choice 1" 2 1 "" { "No attack" "New Bug" "Probe" } 0
    t "" 1 "No Attack" { -20.000, 0.000 }
    c "Find new bug" 1 "" { "Success" 0.4 "Failure" 0.6 } 0
    t "" 2 "New bug, Success" { -120.000, 40.000 }
    t "" 3 "New bug, Failure" { -20.000, -20.000 }
    c "Probe" 2 "" { "Caught" 0.6 "Failure" 0.4 } 0
    t "" 4 "Caught" { -20.000, -10.000 }
    p "Attacker's choice 2" 2 2 "" { "No attack" "New Bug" } 0
    t "" 5 "No Attack" { -20.000, 0.000 }
    c "Find new bug" 3 "" { "Success" 0.4 "Failure" 0.6 } 0
    t "" 6 "New bug, Success" { -120.000, 40.000 }
    t "" 7 "New bug, Failure" { -20.000, -20.000 }
    p "Attacker's choice 1" 2 1 "" { "No attack" "New Bug" "Probe" } 0
    t "" 8 "No Attack" { -10.000, 0.000 }
    c "Find new bug" 4 "" { "Success" 0.9 "Failure" 0.09999999999999998 } 0
    t "" 9 "New bug, Success" { -110.000, 40.000 }
    t "" 10 "New bug, Failure" { -10.000, -20.000 }
    c "Probe" 5 "" { "Caught" 0.9 "Failure" 0.09999999999999998 } 0
    t "" 11 "Caught" { -10.000, -10.000 }
    p "Attacker's choice 2" 2 2 "" { "No attack" "New Bug" } 0
    t "" 12 "No Attack" { -10.000, 0.000 }
    c "Find new bug" 6 "" { "Success" 0.9 "Failure" 0.09999999999999998 } 0
    t "" 13 "New bug, Success" { -110.000, 40.000 }
    t "" 14 "New bug, Failure" { -10.000, -20.000 }
    p "Attacker's choice 1" 2 1 "" { "No attack" "New Bug" "Probe" } 0
    t "" 15 "No Attack" { -10.000, 0.000 }
    c "Find new bug" 7 "" { "Success" 0.4 "Failure" 0.6 } 0
    t "" 16 "New bug, Success" { -110.000, 40.000 }
    t "" 17 "New bug, Failure" { -10.000, -20.000 }
    c "Probe" 8 "" { "Caught" 0.6 "Failure" 0.4 } 0
    t "" 18 "Caught" { -10.000, -10.000 }
    c "Exploit found" 9 "" { "Success" 0.4 "Failure" 0.6 } 0
    t "" 19 "New bug, Success" { -110.000, 50.000 }
    t "" 20 "New bug, Failure" { -10.000, -10.000 }
    p "Attacker's choice 1" 2 1 "" { "No attack" "New Bug" "Probe" } 0
    t "" 21 "No Attack" { 0.000, 0.000 }
    c "Find new bug" 10 "" { "Success" 0.9 "Failure" 0.09999999999999998 } 0
    t "" 22 "New bug, Success" { -100.000, 40.000 }
    t "" 23 "New bug, Failure" { 0.000, -20.000 }
    c "Probe" 11 "" { "Caught" 0.9 "Failure" 0.09999999999999998 } 0
    t "" 24 "Caught" { 0.000, -10.000 }
    c "Exploit found" 12 "" { "Success" 0.9 "Failure" 0.09999999999999998 } 0
    t "" 25 "New bug, Success" { -100.000, 50.000 }
    t "" 26 "New bug, Failure" { 0.000, -10.000 }
    <analysis type="list">
    <profile type="behav">
    0,0,1,0,0,1,0,1/2,1/2

    Thanks for your help.
    Last edited by M0RT; 02-16-2012 at 04:56 AM.

  2. #2
    doWhile is offline Moderator
    Join Date
    Jul 2010
    Location
    California
    Posts
    1,641
    Rep Power
    7

    Default Re: Getting specific values from a file

    Do you know how to read a file? Do you know how to parse text? Do you know anything about regular expressions? The more information you provide - eg what you've attempted for each piece of your problem - the more quality advice you may receive.

  3. #3
    M0RT is offline Member
    Join Date
    Feb 2012
    Posts
    2
    Rep Power
    0

    Default Re: Getting specific values from a file

    Thanks for the tip doWhile.
    I'm trying to use a scanner and setting up delimiters to be "{" and "," and getting nextDouble(). That might work for the lines that start with "t", but not the ones that start with "c". Would setting up IF statements for each kind of delimiter work?

    And to answer your question, I do know how to read from a file and parse text. I hope...

Similar Threads

  1. Taking specific values form Array
    By Eleeist in forum New To Java
    Replies: 17
    Last Post: 02-06-2012, 09:10 PM
  2. Deleting specific chars from a file
    By javauserjava in forum New To Java
    Replies: 10
    Last Post: 04-03-2011, 05:25 PM
  3. Replies: 14
    Last Post: 01-22-2011, 02:36 PM
  4. Replies: 0
    Last Post: 07-15-2010, 01:23 PM
  5. Replies: 2
    Last Post: 11-08-2008, 10:40 AM

Tags for this Thread

Posting Permissions

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