Results 1 to 3 of 3
  1. #1
    mond14 is offline Member
    Join Date
    May 2013
    Posts
    6
    Rep Power
    0

    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".

    ++++++++++++++++++++++++++++++++++++++++++++
    Java Code:
    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
    jim829 is offline Senior Member
    Join Date
    Jan 2013
    Location
    Northern Virginia, United States
    Posts
    3,534
    Rep Power
    5

    Default Re: Character string extraction from a text file

    Clearly that isn't the code you are running since it is not only incomplete but syntactically incorrect (e.g. the argument to the File constructor). In any event, you need to either store the lines in unique variables or read up on arrays and lists.

    Regards,
    Jim
    The Java™ Tutorial | SSCCE | Java Naming Conventions
    Poor planning our your part does not constitute an emergency on my part.

  3. #3
    Junky's Avatar
    Junky is offline Grand Poobah
    Join Date
    Jan 2011
    Location
    Dystopia
    Posts
    3,788
    Rep Power
    7

Similar Threads

  1. Text extraction from pdf word and excel
    By agastheswar in forum Advanced Java
    Replies: 1
    Last Post: 01-21-2012, 09:49 AM
  2. Replies: 5
    Last Post: 03-12-2011, 01:04 AM
  3. count character in text file as input file
    By aNNuur in forum New To Java
    Replies: 7
    Last Post: 03-25-2010, 04:01 PM
  4. Replies: 3
    Last Post: 03-03-2010, 12:23 AM
  5. Replies: 1
    Last Post: 02-04-2008, 08:26 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
  •