Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- import java.io.File;
- import java.io.FileNotFoundException;
- import java.io.PrintWriter;
- /**
- * Write a description of class FileScan here.
- *
- * @author (your name)
- * @version (a version number or a date)
- * @params reserved word, all following must be the names of text files.
- */
- public class FileScan
- {
- public static void main(String[] args) throws FileNotFoundException
- {
- Scanner in = new Scanner(System.in);
- System.out.print(">");
- String inputLine = in.nextLine();
- Scanner parser = new Scanner(inputLine);
- parser.useDelimiter(" ");
- String reservedWord = parser.next();
- System.out.println(inputLine);
- System.out.println(parser);
- String results = null;
- while(parser.hasNext())
- {
- String fileName = parser.next(); // should find each thing after reserved word, which is a filename
- File inFile = new File(fileName);
- Scanner fileScan = new Scanner(inFile);
- while(fileScan.hasNextLine())
- {
- results = results + fileName + ": ";
- if(fileScan.findInLine(reservedWord) == reservedWord)
- {
- results = results + fileScan.nextLine();
- }
- results = results + "\n";
- }
- }
- System.out.print(results);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement