本帖最后由 屈俊材 于 2012-9-26 07:51 编辑
拷贝文件时,是不是使用缓冲流最快了。
还有没有比这更快的。- public static void CopyFile()
- {
- BufferedInputStream bis = null;
- BufferedOutputStream bos = null;
- try
- {
- bis = new BufferedInputStream(new FileInputStream("File.txt"));
- bos = new BufferedOutputStream(new FileOutputStream("CopyFile.txt"));
- byte[] by = new byte[bis.available()];
- bis.read(by);
- bos.write(by);
- }
- catch (IOException e)
- {
- throw new RuntimeException("复制失败");
- }
- finally
- {
- try
- {
- if(bis != null)
- bis.close();
- }
- catch (IOException e)
- {
- throw new RuntimeException("读取关闭失败");
- }
- try
- {
- if(bos != null)
- bos.close();
- }
- catch (IOException e)
- {
- throw new RuntimeException("写入关闭失败");
- }
- }
- }
复制代码 |