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

Thread: Character string extraction from a text file

  1. #1
    Junior Member
    Join Date
    Nov 2013
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Character string extraction from a text file

    Hi,

    Please I am a beginner in java, I want to extract information from a text file. is the following:
    ============================================
    From: 55555565
    From_SMSC: 78987555
    Sent: 00-02-21 22:26:23
    Received: 00-02-21 22:26:29
    Subject: modem1
    Alphabet: ISO
    UDH: false

    pr2
    ============================================

    I want to extract the first line which is exactly the number " 55555565 " and the last line is "pr2".

    for now I just use the code that allows me to extract only the last line"pr2".

    ++++++++++++++++++++++++++++++++++++++++++++
    Scanner scanner = new Scanner(new File(/home/Desktop/ivw.txt));
    String line = null;
    while (scanner.hasNextLine()) {
    line = scanner.nextLine();
    }
     
    readSMS=line;
    scanner.close();
    ++++++++++++++++++++++++++++++++++++++++++++

    I want to retrieve information both the first line and the last line so that I can put each in a variable.

    thank you for your help


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    SW Missouri
    Posts
    20,394
    Thanks
    49
    Thanked 2,212 Times in 2,185 Posts

    Default Re: Character string extraction from a text file

    Change the code to read and save the first line before it reads all the rest of the lines.
    If you don't understand my answer, don't ignore it, ask a question.

  3. #3
    Junior Member
    Join Date
    Nov 2013
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Character string extraction from a text file

    hi,

    the problem is that I do not know how to specify the first line.

  4. #4
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    SW Missouri
    Posts
    20,394
    Thanks
    49
    Thanked 2,212 Times in 2,185 Posts

    Default Re: Character string extraction from a text file

    how to specify the first line
    The first line will be the line that is read first.
    If you don't understand my answer, don't ignore it, ask a question.

  5. #5
    Grand Poobah
    Join Date
    Mar 2011
    Posts
    1,545
    My Mood
    Grumpy
    Thanks
    0
    Thanked 167 Times in 158 Posts

    Default Re: Character string extraction from a text file

    Character string extraction from a text file

    Duplicate post
    Improving the world one idiot at a time!

Similar Threads

  1. Replacing text after a certain character or symbol in a text file
    By Ravekitty in forum File I/O & Other I/O Streams
    Replies: 2
    Last Post: November 25th, 2013, 01:40 PM
  2. Replies: 11
    Last Post: November 12th, 2012, 12:09 PM
  3. Text File into String Array
    By mathanv in forum What's Wrong With My Code?
    Replies: 4
    Last Post: December 12th, 2010, 04:30 AM
  4. reading string in from text file
    By basketball8533 in forum File I/O & Other I/O Streams
    Replies: 4
    Last Post: December 3rd, 2010, 04:31 PM
  5. [SOLVED] Specific Text Extraction from PDF Research paper documents
    By user101 in forum Threads
    Replies: 1
    Last Post: September 8th, 2010, 11:30 AM