Results 1 to 1 of 1
- 03-11-2010, 05:39 AM #1
Member
- Join Date
- Mar 2010
- Posts
- 1
- Rep Power
- 0
Help with reading / searching a .txt file
import java.io.*;
import java.util.Scanner;
public class SearchWord
{
public static void main(String[] args) throws IOException
{
Scanner sc = new Scanner(System.in);
String write;
String read;
String keyword;
int count = 0;
int countword = 0;
File input;
File output;
System.out.println("Enter the name of the file you would ");
System.out.print("like to search(include .txt): ");
read = sc.nextLine();
File searchs = new File(read);
if (!searchs.exists())
{
System.out.println(" The file you would like to search can not be found.");
System.out.print(" Please check the name and run this program again.");
System.exit(0);
}
System.out.println("Enter the name of the file you would ");
System.out.print("like to write to(include .txt): ");
write = sc.nextLine();
output = new File(write);
System.out.print("Enter the word you would like to search for: ");
keyword = sc.nextLine();
Scanner inputFile = new Scanner(searchs);
while (inputFile.hasNext())
{
String search = inputFile.nextLine();
count++;
}
inputFile.close();
System.out.println(count);
System.out.println("help");
}
}
I am new the forum and new to Java. I am a Sophmore Computer Science student. I am just looking for some points in the right direction here. This is a homework assignment and my teacher is very busy and does not have much time to assist.
My error is I need to use my search string outside my loop.
Sorry for the messy script. (its long from done)
Any help would be a blessing.
Thank you for your time,
Abs
Similar Threads
-
Reading and Writing the contents of a file to another file
By priyankatxs in forum New To JavaReplies: 9Last Post: 10-20-2009, 10:52 AM -
[SOLVED] how to reading binary file and writing txt file
By tOpach in forum New To JavaReplies: 3Last Post: 05-09-2009, 11:31 PM -
Searching XML file using DOM
By simon in forum XMLReplies: 5Last Post: 03-30-2009, 01:27 AM -
Searching a string from a text file using Swing Buttons
By pradeep1_mca@yahoo.com in forum AWT / SwingReplies: 2Last Post: 09-15-2008, 09:50 AM -
Searching a String from Text file using Swings .
By pradeep1_mca@yahoo.com in forum AWT / SwingReplies: 4Last Post: 09-09-2008, 05:29 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks