11/*
2- * Copyright 2010-2023 the original author or authors.
2+ * Copyright 2010-2025 the original author or authors.
33 *
44 * Licensed under the Apache License, Version 2.0 (the "License");
55 * you may not use this file except in compliance with the License.
1818import static org .apache .ibatis .migration .utils .Util .file ;
1919
2020import java .io .File ;
21- import java .io .FileReader ;
22- import java .io .FileWriter ;
2321import java .io .IOException ;
2422import java .io .LineNumberReader ;
2523import java .io .OutputStream ;
2826import java .io .Reader ;
2927import java .net .URL ;
3028import java .net .URLClassLoader ;
29+ import java .nio .file .Files ;
30+ import java .nio .file .Path ;
3131import java .text .DecimalFormat ;
3232import java .text .ParseException ;
3333import java .text .SimpleDateFormat ;
@@ -161,7 +161,7 @@ protected void copyResourceTo(String resource, File toFile, Properties variables
161161 protected void copyExternalResourceTo (String resource , File toFile , Properties variables ) {
162162 printStream .println ("Creating: " + toFile .getName ());
163163 try {
164- File sourceFile = new File (resource );
164+ File sourceFile = Path . of (resource ). toFile ( );
165165 copyTemplate (sourceFile , toFile , variables );
166166 } catch (Exception e ) {
167167 throw new MigrationException ("Error copying " + resource + " to " + toFile .getAbsolutePath () + ". Cause: " + e ,
@@ -170,15 +170,15 @@ protected void copyExternalResourceTo(String resource, File toFile, Properties v
170170 }
171171
172172 protected static void copyTemplate (File templateFile , File toFile , Properties variables ) throws IOException {
173- try (FileReader reader = new FileReader (templateFile )) {
173+ try (Reader reader = Files . newBufferedReader (templateFile . toPath () )) {
174174 copyTemplate (reader , toFile , variables );
175175 }
176176 }
177177
178178 protected static void copyTemplate (Reader templateReader , File toFile , Properties variables ) throws IOException {
179179 VariableReplacer replacer = new VariableReplacer (variables );
180180 try (LineNumberReader reader = new LineNumberReader (templateReader );
181- PrintWriter writer = new PrintWriter (new FileWriter (toFile ))) {
181+ PrintWriter writer = new PrintWriter (Files . newBufferedWriter (toFile . toPath () ))) {
182182 String line ;
183183 while ((line = reader .readLine ()) != null ) {
184184 line = replacer .replace (line );
@@ -259,7 +259,7 @@ private ClassLoader getDriverClassLoader() {
259259 private File getCustomDriverPath () {
260260 String customDriverPath = environment ().getDriverPath ();
261261 if (customDriverPath != null && customDriverPath .length () > 0 ) {
262- return new File (customDriverPath );
262+ return Path . of (customDriverPath ). toFile ( );
263263 }
264264 return options .getPaths ().getDriverPath ();
265265 }
0 commit comments