Advertisement
Guest User

Untitled

a guest
Jul 15th, 2019
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.67 KB | None | 0 0
  1. File text = new File("Fahrzeug.txt");
  2. FileWriter writer;
  3.  
  4. Nummer14Auto auto = new Nummer14Auto("Grün", 4, true);
  5. Nummer14Fahrrad fahrrad = new Nummer14Fahrrad("Pink", 2, true);
  6.  
  7. try {
  8. writer = new FileWriter(text);
  9. writer.write(auto.toString() + "\n");
  10. writer.write(fahrrad.toString());
  11.  
  12. writer.flush();
  13. writer.close();
  14. } catch (IOException e) {
  15. e.printStackTrace();
  16. }
  17. if(text.exists()){
  18. try {
  19. Scanner sc = new Scanner(text);
  20.  
  21. while(sc.hasNext()){
  22. System.out.println(sc.next() + " ");
  23. }
  24.  
  25. sc.close();
  26.  
  27. } catch (FileNotFoundException e1) {
  28. e1.printStackTrace();
  29. }
  30. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement