要使用fs.copyFile()方法,您需要先导入fs模块。然后,您可以使用以下语法调用copyFile()方法:
fs.copyFile(srcPath, destPath, callback)参数说明:
srcPath:要复制的源文件路径。destPath:要复制到的目标文件路径。callback:回调函数,用于在复制完成后执行。以下是一个使用fs.copyFile()的例子:
const fs = require('fs');// 定义源文件和目标文件路径const srcPath = 'path/to/source/file.txt';const destPath = 'path/to/destination/file.txt';// 调用copyFile()方法进行复制fs.copyFile(srcPath, destPath, (err) => { if (err) { console.error(err); return; } console.log('文件复制成功!');});请确保源文件和目标文件的路径是正确的,并且您对目标文件的父文件夹具有写入权限。

