File search program

Word search in a file

Page 1 of 1

2 Replies - 3137 Views - Last Post: 22 November 2010 - 06:37 AM Rate Topic: -----

#1 Evey  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 22-November 10

File search program

Posted 22 November 2010 - 05:59 AM

Hey!
Im new to java and need some help
constructing a program that do as follows:

Searches all files specified by the user
on the command line and prints out all
lines containg a reserved word.

java searchWord ring message.txt address.txt printer.java

then it might print it like this

message.txt: has broken up through the ring of DVD botleggers.
address.txt: Manning Ringle, New York.
printer.java: String filename;

here is the code so far:

public class SearchWord {
static String keyword;
static int lineID;

public static void main(String[] args) throws Exception
Scanner fileScanner = new Scanner(new File(fileName));

if(args.length < 2)
{
System.out.print("Usage: java Search keyword sourcefile1 sourcefile2 sourcefile3");

return;
}

keyword = args[0]
for(i = 1; i < args.length; i++)
{
String temp;
String filename = args[i]
reader = new BufferedReader (new FileReader(filename));
tem = reader.readLine();

System.out.println("Enter a filenames");
String filename = in.next();
}




I need some help
how I can go get this result
and help with the code

Is This A Good Question/Topic? 0
  • +

Replies To: File search program

#2 Evey  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 22-November 10

Re: File search program

Posted 22 November 2010 - 06:15 AM

View PostEvey, on 22 November 2010 - 04:59 AM, said:

Hey!
Im new to java and need some help
constructing a program that do as follows:

Searches all files specified by the user
on the command line and prints out all
lines containg a reserved word.

java searchWord ring message.txt address.txt printer.java

then it might print it like this

message.txt: has broken up through the ring of DVD botleggers.
address.txt: Manning Ringle, New York.
printer.java: String filename;

here is the code so far:

public class SearchWord {
static String keyword;
static int lineID;

public static void main(String[] args) throws Exception
Scanner fileScanner = new Scanner(new File(fileName));

if(args.length < 2)
{
System.out.print("Usage: java Search keyword sourcefile1 sourcefile2 sourcefile3");

return;
}

keyword = args[0]
for(i = 1; i < args.length; i++)
{
String temp;
String filename = args[i]
reader = new BufferedReader (new FileReader(filename));
tem = reader.readLine();

System.out.println("Enter a filenames");
String filename = in.next();
}




I need some help
how I can go get this result
and help with the code



correcting myself

public class SearchWord {
static String keyword;
static int lineID;

public static void main(String[] args) throws Exception
Scanner fileScanner = new Scanner(new File(fileName));

if(args.length < 2)
{
System.out.print("Usage: java Search keyword sourcefile1 sourcefile2 sourcefile3");

return;
}

keyword = args[0]
for(i = 1; i < args.length; i++)
{
String temp;
String filename = args[i]
reader = new BufferedReader (new FileReader(filename));
temp = reader.readLine();
}


Was This Post Helpful? 0
  • +
  • -

#3 g00se  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 2656
  • View blog
  • Posts: 11,205
  • Joined: 20-September 08

Re: File search program

Posted 22 November 2010 - 06:37 AM

Quote

System.out.println("Enter a filenames");


I'm confused - you've specified file names as arguments to the application...

This post has been edited by g00se: 22 November 2010 - 06:38 AM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1