Results 1 to 2 of 2
  1. #1
    Plex is offline Member
    Join Date
    Nov 2010
    Rep Power

    Default Reading specific portions of text file

    Hey Java experts!

    I just had a quick question.

    I spent a lot of time looking around, but I can't find a real answer. I'm looking for a way to parse a (very) long text file and pull a piece of it and write it to a next text file.

    I found that I could replace pieces, and that worked to an extent (by replacing the parts of the lines I didn't need with a blank to remove them).

    The file has lines that look like this:

    2010-11-09 09:55:15:691 - () Unable to lock Claim=10XXX30E0XXXX, Error Code=60016

    Some lines don't have claim numbers on them at all. What I want to do is extract just that claim number, nothing else. I want a new file that lists just the claim numbers.

    I suppose what I'm trying to find out is if Java has some way to look at a line and say something like "ok, here's the word 'claim,' now I want to extract the 12 characters immediately following it."

    As always, thank you all for your time and help <3.

  2. #2
    StormyWaters is offline Senior Member
    Join Date
    Feb 2009
    Rep Power


    Check the String API
    String (Java 2 Platform SE 5.0)

    Specifically you can use the contains() method to determine if its a line you want to further parse, and a combination of the indexOf() and substring() methods to obtain the claim number.

Similar Threads

  1. Help reading a text file.
    By Kristoba in forum New To Java
    Replies: 5
    Last Post: 03-11-2010, 08:42 AM
  2. writing to specific line in text file
    By mickmos in forum New To Java
    Replies: 2
    Last Post: 04-18-2009, 01:01 PM
  3. Writing To A Specific Text File Line
    By mokonji in forum New To Java
    Replies: 1
    Last Post: 03-02-2009, 08:13 PM
  4. Reading data from csv file based on specific input
    By jaiminparikh in forum Advanced Java
    Replies: 14
    Last Post: 02-13-2009, 09:07 PM
  5. Reading text file
    By Lennon-Guru in forum New To Java
    Replies: 1
    Last Post: 12-15-2007, 11:38 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