Guest User

Untitled

a guest
Jul 17th, 2018
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.28 KB | None | 0 0
  1. import shipment of April 12, 2007
  2. # tab separated data
  3. Bird Golden Eagle Eddie
  4. Mammal Tiger Tommy
  5. Mammal Lion Leo
  6. Mammal Elephant Eddie
  7. Bird Parrot Polly
  8. # last one next
  9. Reptile Cobra Colin
  10.  
  11. public void readDataFromFile() throws FileNotFoundException
  12. {
  13. fileName = fileDialogBox.getFile();
  14. String directoryPath = fileDialogBox.getDirectory();
  15.  
  16. File dataFile = new File (fileName);
  17. Scanner scanner = new Scanner(dataFile);
  18. scanner.useDelimiter("\t");
  19.  
  20. scanner.next();
  21. while(scanner.hasNextLine())
  22. {
  23. String type = scanner.next();
  24. String species = scanner.next();
  25. String name = scanner.next();
  26. System.out.println(type + " " + species + " " + name);
  27. scanner.nextLine();
  28. addAnimal( new Animal(species, name, this) );
  29. }
  30.  
  31. scanner.close();
  32. }
  33.  
  34. }
  35.  
  36. boolean firstTime = true;
  37. while(scanner.hasNextLine())
  38. {
  39. if(firstTime)
  40. {
  41. scanner.nextLine();
  42. firstTime=false;
  43. }
  44. String type = scanner.next();
  45. String species = scanner.next();
  46. String name = scanner.next();
  47. System.out.println(type + " " + species + " " + name);
  48. scanner.nextLine();
  49. addAnimal( new Animal(species, name, this) );
  50. }
Add Comment
Please, Sign In to add comment