Advertisement
Guest User

Untitled

a guest
Dec 18th, 2017
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.80 KB | None | 0 0
  1. public static void sumujIZapisz(String nazwaPliku) throws IOException{
  2.         BufferedReader plik2 = null;
  3.         FileWriter plik4 = null;
  4.  
  5.         int wynik=0;
  6.         String l = "";
  7.         int licznik=1;
  8.         try {
  9.             plik2 = new BufferedReader(new FileReader(nazwaPliku));
  10.            
  11.  
  12.             while ((l = plik2.readLine()) != null) {
  13.                 System.out.println(l);
  14.                 wynik+=Integer.parseInt(l);
  15.  
  16.             }
  17.  
  18.             plik4=new FileWriter(nazwaPliku,true);
  19.  
  20.             wynik+=1;
  21.             plik4.write("\r\n" + Integer.toString(wynik));
  22.  
  23.  
  24.         } finally {
  25.             if (plik2 != null) {
  26.                 plik2.close();
  27.             }
  28.             if (plik4 != null){
  29.                 plik4.close();
  30.             }
  31.  
  32.         }
  33.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement