Write a program Search that searches all files specified on the command line and prints out all lines containing a keyword. For example, if you call
java Search Buff code.txt address.txt Assignment.java
then the program might print
code.txt: Buffer style lunch will be available at the
here is my code
class Search {
public static void main(String args[]){
BufferedReader br = null;
String pattern, s;
int numInputFiles, ctr;
numInputFiles = args.length - 1;
pattern = new String ();
s = new String ();
pattern = args[0];
for (ctr = 0; ctr < numInputFiles; ctr++){
try {
br = new BufferedReader (new FileReader (args[ctr+1]));
s = br.readLine ();
}catch (Exception e) {
System.out.println (e);
}
while (s!=null) {
if( s.indexOf (pattern) >= 0) {
System.out.print(args[ctr+1] + ": ");
System.out.println (s);
}
try {
s = br.readLine ();
} catch (Exception e) {
System.out.println (e);
}
}
}
try{
br.close();
} catch(Exception e){
System.out.println(e);
}
}
}
Im getting some problems here and I hope you
can put me in the right direction


Sign In
Create Account


Back to top









