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();