Advertisement
Guest User

Untitled

a guest
Dec 13th, 2017
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.72 KB | None | 0 0
  1.  
  2. package środa2;
  3.  
  4. import java.io.FileWriter;
  5. import java.io.FileReader;
  6. import java.io.PrintWriter;
  7. import java.io.BufferedReader;
  8. import java.io.IOException;
  9.  
  10. public class txt {
  11.  
  12. static void zapisz(String s){
  13. try{
  14. FileWriter fw = new FileWriter("moj.txt", true);
  15. fw.write(s);
  16. fw.close();
  17. }catch(IOException e){
  18. System.out.println("Błąd wyjścia");
  19. }
  20. }
  21.  
  22. static void zapisz_wiersz(String s){
  23. try{
  24. PrintWriter pw = new PrintWriter(new FileWriter("moj.txt", true));
  25. pw.println(s);
  26. pw.close();
  27. }catch(IOException e){
  28. System.out.println("Błąd wyjścia");
  29. }
  30. }
  31.  
  32. static void odczyt(){
  33. try{
  34. FileReader fr = new FileReader("moj.txt");
  35. int i;
  36. do{
  37. i = fr.read();
  38. System.out.print((char)i);
  39. }while(i != -1);
  40. fr.close();
  41. }catch(IOException e){
  42. System.out.println("Błąd wejścia");
  43. }
  44.  
  45. }
  46.  
  47. static void odczyt_wierszy(){
  48. try{
  49. BufferedReader br = new BufferedReader(new FileReader("moj.txt"));
  50. String s;
  51.  
  52. do{
  53.  
  54. s = br.readLine();
  55. System.out.println(s);
  56. }
  57. while(s != null);
  58. br.close();
  59.  
  60.  
  61. }catch(IOException e){
  62. System.out.println("Błąd wejścia");
  63. }
  64. }
  65.  
  66. public static void main(String[] args) {
  67. //zapisz("Idzie zima \n");
  68. //zapisz_wiersz("Idzie zima");
  69. //odczyt();
  70. odczyt_wierszy();
  71.  
  72.  
  73.  
  74. }
  75.  
  76. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement