From 96fb5d72eb40a0ecfc13fbdf229477b61d97c526 Mon Sep 17 00:00:00 2001 From: Patrick Strawderman Date: Thu, 22 Jan 2026 21:28:41 -0600 Subject: [PATCH] Use Reader.transferTo in FileCopyUtils Use the transferTo method in FileCopyUtils#copy(Reader, Writer). Closes gh-36196 Signed-off-by: Patrick Strawderman --- .../main/java/org/springframework/util/FileCopyUtils.java | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/spring-core/src/main/java/org/springframework/util/FileCopyUtils.java b/spring-core/src/main/java/org/springframework/util/FileCopyUtils.java index d89086c68cc..fcfea916de9 100644 --- a/spring-core/src/main/java/org/springframework/util/FileCopyUtils.java +++ b/spring-core/src/main/java/org/springframework/util/FileCopyUtils.java @@ -168,13 +168,7 @@ public abstract class FileCopyUtils { Assert.notNull(out, "No Writer specified"); try { - int charCount = 0; - char[] buffer = new char[BUFFER_SIZE]; - int charsRead; - while ((charsRead = in.read(buffer)) != -1) { - out.write(buffer, 0, charsRead); - charCount += charsRead; - } + int charCount = (int) in.transferTo(out); out.flush(); return charCount; }