Results 1 to 6 of 6
- 09-28-2010, 02:13 PM #1
- 09-28-2010, 03:52 PM #2
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.
- 09-30-2010, 09:58 AM #3
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();
- 09-30-2010, 12:59 PM #4
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.why it doesn't know what Query1 is
- 09-30-2010, 12:59 PM #5
Moderator
- Join Date
- Apr 2009
- Posts
- 10,484
- Rep Power
- 16
You defined Query1 in the while block, so it isn't visible outside that block.
ETA: Bah!
- 09-30-2010, 01:03 PM #6
Similar Threads
-
Finding Jar files in a class file
By bnrkcdc in forum Jobs DiscussionReplies: 4Last Post: 09-08-2010, 01:46 PM -
Read in words from a text file that contains a story
By Pleenen in forum Advanced JavaReplies: 2Last Post: 05-27-2010, 04:34 AM -
[SOLVED] Trouble with Scanner FileInputStream not finding the file
By miss.meli in forum New To JavaReplies: 0Last Post: 12-01-2008, 09:50 PM -
help...! about reading a text file and finding their average
By nemesis in forum New To JavaReplies: 20Last Post: 10-20-2008, 11:02 AM -
Finding the character set of a FILE
By javaplus in forum Advanced JavaReplies: 1Last Post: 01-22-2008, 06:36 AM


LinkBack URL
About LinkBacks

Bookmarks