diff --git a/src/main/java/org/openrewrite/java/migrate/apache/commons/io/ApacheCommonsFileUtils.java b/src/main/java/org/openrewrite/java/migrate/apache/commons/io/ApacheCommonsFileUtils.java index 5113c05e41..e7a5d24570 100644 --- a/src/main/java/org/openrewrite/java/migrate/apache/commons/io/ApacheCommonsFileUtils.java +++ b/src/main/java/org/openrewrite/java/migrate/apache/commons/io/ApacheCommonsFileUtils.java @@ -20,6 +20,7 @@ import org.apache.commons.io.FileUtils; import java.io.File; +import java.nio.file.Files; public class ApacheCommonsFileUtils { private static class GetFile { @@ -47,5 +48,18 @@ File after(String name) { // } // } + @SuppressWarnings("deprecation") + private static class WriteStringToFile { + @BeforeTemplate + void before(File a, String s) throws Exception { + FileUtils.writeStringToFile(a, s); + } + + @AfterTemplate + void after(File a, String s) throws Exception { + Files.write(a.toPath(), s.getBytes()); + } + } + } diff --git a/src/test/java/org/openrewrite/java/migrate/apache/commons/io/ApacheCommonsFileUtilsTest.java b/src/test/java/org/openrewrite/java/migrate/apache/commons/io/ApacheCommonsFileUtilsTest.java index 01682289b3..fb3221cb02 100644 --- a/src/test/java/org/openrewrite/java/migrate/apache/commons/io/ApacheCommonsFileUtilsTest.java +++ b/src/test/java/org/openrewrite/java/migrate/apache/commons/io/ApacheCommonsFileUtilsTest.java @@ -98,6 +98,7 @@ void bar(File fileA, File fileB, URL url, Charset cs, FileFilter filter, CharSeq import java.io.FileFilter; import java.net.URL; import java.nio.charset.Charset; + import java.nio.file.Files; import java.util.Collection; import java.util.Collections; import java.util.List; @@ -142,7 +143,7 @@ void bar(File fileA, File fileB, URL url, Charset cs, FileFilter filter, CharSeq strList = FileUtils.readLines(fileA, cs); FileUtils.writeByteArrayToFile(fileA, bytes); FileUtils.writeLines(fileA, collection); - FileUtils.writeStringToFile(fileA, s); + Files.write(fileA.toPath(), s.getBytes()); } } """