Advertisement
Guest User

Untitled

a guest
May 29th, 2016
53
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.28 KB | None | 0 0
  1. import java.io.*;
  2. import java.util.*;
  3.  
  4. public class Anagram{
  5. public static void main(String[] args) throws IOException{
  6.  
  7. Scanner fileScan = new Scanner(new FileInputStream("dictionary.txt"));
  8. String st;
  9. StringBuilder sb;
  10. DictInterface D = new MyDictionary();
  11. // Change MyDictionary() above to DLB() to test your DLB
  12.  
  13. while (fileScan.hasNext())
  14. {
  15. st = fileScan.nextLine();
  16. D.add(st);
  17. }
  18.  
  19. String filename = getFilename();
  20. File anagramData = new File(filename);
  21.  
  22. Scanner inFile = new Scanner(anagramData);
  23. ArrayList<String> wordHolder = new ArrayList<String>();
  24.  
  25. String tempWord = inFile.next();
  26. while(inFile.hasNext()){
  27. wordHolder.add(tempWord);
  28. }
  29.  
  30. inFile.close();
  31.  
  32. }
  33.  
  34. public static String getFilename() throws FileNotFoundException {
  35. String filename = "";
  36. File confirm = new File(filename);
  37. boolean invalid = true;
  38.  
  39. Scanner keyboard = new Scanner(System.in);
  40. do{
  41. System.out.print("Please enter the name of the inventory file: ");
  42. filename = keyboard.nextLine();
  43. confirm = new File(filename);
  44. if(!confirm.exists()){
  45. System.out.println("\nThe file does not exist or is invalid.");
  46. }
  47. else{
  48. invalid = false;
  49. }
  50. }while(invalid == true);
  51.  
  52. return filename;
  53. }
  54. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement