Advertisement
Guest User

Untitled

a guest
Jul 27th, 2017
56
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.71 KB | None | 0 0
  1. package a_Zadania.d_Dzien_4.b_Pliki;
  2.  
  3. import java.io.FileWriter;
  4. import java.io.IOException;
  5. import java.util.Scanner;
  6.  
  7. public class Main1 {
  8.  
  9. public static void main(String[] args) {
  10.  
  11. System.out.println("Podaj linie:");
  12. Scanner scan = new Scanner(System.in);
  13. FileWriter out;
  14. try {
  15. out = new FileWriter("tekst3.txt", true); // true dopisuje; false nadpisze plik.
  16.  
  17. while (scan.hasNextLine()) {
  18. //String s = scan.next(); // słowo po słowie
  19. String s = scan.nextLine(); // linia po linii
  20.  
  21. if (s.equals("quit")) {
  22. System.out.println("Exit");
  23. break;
  24. } else {
  25. out.append(s + "\n");
  26. }
  27.  
  28. }
  29. out.close();
  30. } catch (IOException e) {
  31. e.printStackTrace();
  32. }
  33.  
  34. scan.close();
  35. }
  36. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement