radko93

buforowe

Feb 5th, 2013
38
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.88 KB | None | 0 0
  1. import java.util.*;
  2. import java.io.*;
  3.  
  4. public class kbajtowe {
  5.     int licznik = 0;
  6.     Scanner sc = new Scanner(System.in);
  7.  
  8.     String f1 = sc.nextLine();
  9.     String f2 = sc.nextLine();
  10.  
  11.     public void kopiuj(String f1, String f2) {
  12.         try {
  13.            
  14.             BufferedInputStream br1 = new BufferedInputStream(
  15.                     new FileInputStream(f1));
  16.             BufferedOutputStream br2 = new BufferedOutputStream(
  17.                     new FileOutputStream(f2));
  18.             BufferedInputStream br3 = new BufferedInputStream(
  19.                     new FileInputStream(f1));
  20.  
  21.             while (br1.read()!=-1) {
  22.                 br2.write(br3.read());
  23.                 licznik++;
  24.             }
  25.             System.out.printf("%s%7d", "Liczba bajtow:", licznik);
  26.             br1.close();
  27.             br2.close();
  28.         }
  29.  
  30.         catch (IOException e) {
  31.             System.out.println(e);
  32.         }
  33.     }
  34.  
  35.     public static void main(String[] args) {
  36.         System.out.println("Wprowadz nazwy plikow");
  37.         kbajtowe test = new kbajtowe();
  38.         test.kopiuj(test.f1, test.f2);
  39.  
  40.     }
  41.  
  42. }
Advertisement
Add Comment
Please, Sign In to add comment