From 71404dcfbd2d8b6754a04503797a0ac817ecb3e7 Mon Sep 17 00:00:00 2001 From: MrDecadent <82100995+MrDecadent@users.noreply.github.com> Date: Thu, 28 Jul 2022 15:16:01 +0800 Subject: [PATCH] Update io-basis.md MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit JAVA IO基础知识总结中的字节缓冲流,对复制一个PDF文件的举例测试代码,位置相反了 --- docs/java/io/io-basis.md | 36 ++++++++++++++++++------------------ 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/docs/java/io/io-basis.md b/docs/java/io/io-basis.md index 16c83303ecf..910532b32e9 100755 --- a/docs/java/io/io-basis.md +++ b/docs/java/io/io-basis.md @@ -305,15 +305,14 @@ BufferedInputStream bufferedInputStream = new BufferedInputStream(new FileInputS ```java @Test -void copy_pdf_to_another_pdf_with_byte_array_buffer_stream() { +void copy_pdf_to_another_pdf_buffer_stream() { // 记录开始时间 long start = System.currentTimeMillis(); try (BufferedInputStream bis = new BufferedInputStream(new FileInputStream("深入理解计算机操作系统.pdf")); BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream("深入理解计算机操作系统-副本.pdf"))) { - int len; - byte[] bytes = new byte[4 * 1024]; - while ((len = bis.read(bytes)) != -1) { - bos.write(bytes, 0, len); + int content; + while ((content = bis.read()) != -1) { + bos.write(content); } } catch (IOException e) { e.printStackTrace(); @@ -324,15 +323,14 @@ void copy_pdf_to_another_pdf_with_byte_array_buffer_stream() { } @Test -void copy_pdf_to_another_pdf_with_byte_array_stream() { +void copy_pdf_to_another_pdf_stream() { // 记录开始时间 long start = System.currentTimeMillis(); try (FileInputStream fis = new FileInputStream("深入理解计算机操作系统.pdf"); FileOutputStream fos = new FileOutputStream("深入理解计算机操作系统-副本.pdf")) { - int len; - byte[] bytes = new byte[4 * 1024]; - while ((len = fis.read(bytes)) != -1) { - fos.write(bytes, 0, len); + int content; + while ((content = fis.read()) != -1) { + fos.write(content); } } catch (IOException e) { e.printStackTrace(); @@ -358,14 +356,15 @@ void copy_pdf_to_another_pdf_with_byte_array_stream() { ```java @Test -void copy_pdf_to_another_pdf_buffer_stream() { +void copy_pdf_to_another_pdf_with_byte_array_buffer_stream() { // 记录开始时间 long start = System.currentTimeMillis(); try (BufferedInputStream bis = new BufferedInputStream(new FileInputStream("深入理解计算机操作系统.pdf")); BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream("深入理解计算机操作系统-副本.pdf"))) { - int content; - while ((content = bis.read()) != -1) { - bos.write(content); + int len; + byte[] bytes = new byte[4 * 1024]; + while ((len = bis.read(bytes)) != -1) { + bos.write(bytes, 0, len); } } catch (IOException e) { e.printStackTrace(); @@ -376,14 +375,15 @@ void copy_pdf_to_another_pdf_buffer_stream() { } @Test -void copy_pdf_to_another_pdf_stream() { +void copy_pdf_to_another_pdf_with_byte_array_stream() { // 记录开始时间 long start = System.currentTimeMillis(); try (FileInputStream fis = new FileInputStream("深入理解计算机操作系统.pdf"); FileOutputStream fos = new FileOutputStream("深入理解计算机操作系统-副本.pdf")) { - int content; - while ((content = fis.read()) != -1) { - fos.write(content); + int len; + byte[] bytes = new byte[4 * 1024]; + while ((len = fis.read(bytes)) != -1) { + fos.write(bytes, 0, len); } } catch (IOException e) { e.printStackTrace();