evgeniyosipov

BuffFileCopy.java

Mar 30th, 2014
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.37 KB | None | 0 0
  1. import java.io.*;
  2.  
  3. public class BuffFileCopy {
  4.  
  5.  /**
  6.   * @param args
  7.   */
  8.  public static void main(String[] args) throws IOException {
  9.  
  10.   FileInputStream inFile = null;
  11.   FileOutputStream outFile = null;
  12.   BufferedInputStream inBuff =null;
  13.   BufferedOutputStream outBuffO =null;
  14.  
  15.   try {
  16.  
  17.    // Поток ввода соединяется с буфером
  18.    inFile = new FileInputStream("c:\\bufffilecopy\\ubuntu-12.04-beta1-desktop-i386.iso");
  19.    inBuff = new BufferedInputStream(inFile);
  20.  
  21.    // Поток вывода соединяется с буфером
  22.    outFile = new FileOutputStream("c:\\bufffilecopy2\\ubuntu-12.04-beta1-desktop-i386.iso");
  23.    outBuffO = new BufferedOutputStream(outFile);
  24.  
  25.    while (true) {
  26.     // Считывается байт данных и записывается
  27.     // в буфер вывода данных
  28.     int intValueOfByte = inBuff.read();
  29.     outBuffO.write(intValueOfByte);
  30.  
  31.     if (intValueOfByte == -1){
  32.     break;
  33.     }
  34.  
  35.            }
  36.    } catch (IOException e) {
  37.    e.printStackTrace();
  38.  
  39.       } finally{
  40.  
  41.    try{
  42.     // Сброс данных в поток вывода и
  43.     // закритие потоков
  44.     outBuffO.flush();
  45.     inBuff.close();
  46.     inFile.close();
  47.     outFile.close();
  48.  
  49.        } catch (Exception e1) {
  50.     e1.printStackTrace();
  51.        }
  52.    }
  53.         }
  54.        }
Advertisement
Add Comment
Please, Sign In to add comment