Advertisement
Guest User

javawej

a guest
Jan 24th, 2019
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.98 KB | None | 0 0
  1. /*
  2. * To change this license header, choose License Headers in Project Properties.
  3. * To change this template file, choose Tools | Templates
  4. * and open the template in the editor.
  5. */
  6. package wejsciowkastrumienie2;
  7.  
  8. import java.io.BufferedReader;
  9. import java.io.BufferedWriter;
  10. import java.io.FileInputStream;
  11. import java.io.FileOutputStream;
  12. import java.io.FileReader;
  13. import java.io.FileWriter;
  14. import java.io.IOException;
  15. import java.io.LineNumberReader;
  16. import java.util.Scanner;
  17.  
  18. /**
  19. *
  20. * @author lenovo
  21. */
  22. public class WejsciowkaStrumienie2 {
  23.  
  24. public static void main(String[] args) throws IOException
  25. {
  26. BufferedReader czytanie = null;
  27. BufferedWriter zapisywanie = null;
  28. LineNumberReader w= null;
  29. String nazwa;
  30. Scanner sc = new Scanner(System.in);
  31. try
  32. {
  33. System.out.println("Podaj nazwe pliku: ");
  34. nazwa = sc.nextLine();
  35. System.out.println(nazwa);
  36. czytanie = new BufferedReader (new FileReader(nazwa));
  37. zapisywanie = new BufferedWriter (new FileWriter(""));
  38. w = new LineNumberReader(czytanie);
  39. i = w.getLineNumber();
  40.  
  41. }
  42. catch (IOException ex)
  43. {
  44. System.err.println("nie moge odpalic pliku");
  45. }
  46. try
  47. {
  48. String line = "";
  49. while(!"quit".equals(line))
  50. {
  51. System.out.println( "podaj co chcesz zapisac do pliku: ");
  52. line = sc.nextLine();
  53. zapisywanie.write(line);
  54. zapisywanie.newLine();
  55. System.out.println(line);
  56. }
  57. }
  58.  
  59. catch(IOException e)
  60. {
  61. System.out.println("Błąd");
  62. }
  63. finally
  64. {if (czytanie!=null) czytanie.close();
  65. if(zapisywanie!=null) zapisywanie.close();
  66. }
  67. }
  68. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement