Results 1 to 6 of 6
  1. #1
    Lund01's Avatar
    Lund01 is offline Senior Member
    Join Date
    Sep 2010
    Location
    The Netherlands
    Posts
    149
    Rep Power
    0

    Post Finding words (and more) in another file

    Java Code:
     
    :)
    But I need some help on how to continue....
    Last edited by Lund01; 10-07-2010 at 01:07 PM.

  2. #2
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,305
    Rep Power
    25

    Default

    One file contains the "key/search" String and nothing more. One per line.
    The other file contains lines that start with the "key" Strings and are followed by some data.
    You want to find all the lines in the other file that start with a "key/search" String.

    Read all the search strings into an array or collection.
    Read the other file line by line and check each line against each of the contents of the saved array of search strings. If the line starts with the search string, write it out to the new file.

  3. #3
    Lund01's Avatar
    Lund01 is offline Senior Member
    Join Date
    Sep 2010
    Location
    The Netherlands
    Posts
    149
    Rep Power
    0

    Default ArrayList

    I am trying to add an ArrayList to it.
    But it don't understand why it doesn't know what Query1 is.
    Becose I defined them as the words who are in the file...

    Java Code:
     
    				// Read text from the file.
    				// Query1 = Words in the readed file.
    				while (input1.hasNext()) {
    					String Query1 = input1.next();
    					System.out.println(Query1);
    					//System.out.println(input1.nextLine());
    				}
    
    				// Create an ArrayList.
    				java.util.ArrayList fileList = new java.util.ArrayList();
    				fileList.add(Query1);
    
    				// Close the file.
    				input1.close();

  4. #4
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,305
    Rep Power
    25

    Default

    why it doesn't know what Query1 is
    Its a scope problem. You have defined Query1 within a pair of {}s. It is NOT known outside of those enclosing {}s. Move its definition out of the {} so that it is defined within the same {} as the code that needs to use its value.

  5. #5
    Tolls is online now Moderator
    Join Date
    Apr 2009
    Posts
    11,796
    Rep Power
    19

    Default

    You defined Query1 in the while block, so it isn't visible outside that block.

    ETA: Bah!

  6. #6
    Lund01's Avatar
    Lund01 is offline Senior Member
    Join Date
    Sep 2010
    Location
    The Netherlands
    Posts
    149
    Rep Power
    0

Similar Threads

  1. Finding Jar files in a class file
    By bnrkcdc in forum Jobs Discussion
    Replies: 4
    Last Post: 09-08-2010, 01:46 PM
  2. Read in words from a text file that contains a story
    By Pleenen in forum Advanced Java
    Replies: 2
    Last Post: 05-27-2010, 04:34 AM
  3. Replies: 0
    Last Post: 12-01-2008, 09:50 PM
  4. Replies: 20
    Last Post: 10-20-2008, 11:02 AM
  5. Finding the character set of a FILE
    By javaplus in forum Advanced Java
    Replies: 1
    Last Post: 01-22-2008, 06:36 AM

Posting Permissions

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