| AntonSaburov |
Дата 2.11.2004, 13:12 (ссылка)
  |   (нет голосов)
Загрузка ...
|
|
|

Штурман
   
Профиль
Группа: Модератор
Сообщений: 5658
Регистрация: 2.7.2002
Где: Санкт-Петербург
Репутация: 51 Всего: 118
|
Спасибо большое SmaLL за предоставленную информациюВопрос: Копирование файлов стандартными средствами Ответ:| Код | public class FileIO { /** Размер блока. */ protected static final int MINBLOCKSIZE = 4096; /** Копирование файла по блокам. */ public synchronized void copyFileBuffered(String source, String destination, int buffersize) throws FileNotFoundException, IOException { InputStream in = new FileInputStream(source); OutputStream out = new FileOutputStream(destination); if (buffersize <= 0 ) buffersize = MINBLOCKSIZE; int len = 0, count = 0; byte[] b = new byte[buffersize]; while ((count = in.read(b)) != -1) { out.write(b, 0, count); len += count; } in.close(); out.flush(); out.close(); } /** Копирование потоков. */ public synchronized void copyFile(InputStream in, OutputStream out) throws IOException { int len = 0, b = 0; while ((b = in.read()) != -1) { out.write(b); len += b; } in.close(); out.flush(); out.close(); } /** Простое копирование файлов. */ public synchronized void copyFile(String source, String destination) throws FileNotFoundException, IOException { BufferedInputStream in = new BufferedInputStream(new FileInputStream(source)); BufferedOutputStream out = new BufferedOutputStream(new FileOutputStream(destination)); this.copyFile(in, out); } //.... } |
и ещЁ | Код | try { FileChannel source = new FileInputStream("Source file name").getChannel(); FileChannel destination = new FileOutputStream("Destination file name").getChannel(); destination.transferFrom(source, 0, source.size()); source.close(); destination.close(); } catch (IOException e) { } |
|
|
|
|