Advertisement
Guest User

Untitled

a guest
Sep 25th, 2017
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.47 KB | None | 0 0
  1. import java.util.Scanner;
  2. import java.io.File;
  3. import java.io.FileNotFoundException;
  4. import java.io.PrintWriter;
  5. /**
  6. * Write a description of class FileScan here.
  7. *
  8. * @author (your name)
  9. * @version (a version number or a date)
  10. * @params reserved word, all following must be the names of text files.
  11. */
  12. public class FileScan
  13. {
  14. public static void main(String[] args) throws FileNotFoundException
  15. {
  16.  
  17. Scanner in = new Scanner(System.in);
  18.  
  19. System.out.print(">");
  20.  
  21.  
  22. String inputLine = in.nextLine();
  23.  
  24.  
  25. Scanner parser = new Scanner(inputLine);
  26.  
  27. parser.useDelimiter(" ");
  28. String reservedWord = parser.next();
  29. System.out.println(inputLine);
  30.  
  31. System.out.println(parser);
  32. String results = null;
  33. while(parser.hasNext())
  34. {
  35. String fileName = parser.next(); // should find each thing after reserved word, which is a filename
  36.  
  37.  
  38. File inFile = new File(fileName);
  39. Scanner fileScan = new Scanner(inFile);
  40.  
  41. while(fileScan.hasNextLine())
  42. {
  43. results = results + fileName + ": ";
  44. if(fileScan.findInLine(reservedWord) == reservedWord)
  45. {
  46. results = results + fileScan.nextLine();
  47.  
  48. }
  49. results = results + "\n";
  50. }
  51. }
  52. System.out.print(results);
  53. }
  54. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement