美文网首页
nodejs 复制文件

nodejs 复制文件

作者: Hi小胡 | 来源:发表于2018-07-23 14:53 被阅读13次
    function readFile(path, filename, func) {
        fs.readFile(path + "/" + filename, 'utf-8', function (err, data) {
            if (err) {
                console.log("读取失败");
            } else {
                func(data);
            }
        });
    }
    
    function writeFile(path, data, filename) {
        fs.writeFile(path + "/" + filename.split(".")[0] + "2." + filename.split(".")[1], data, function (error) {
            if (error) {
                throw error;
            } else {
                console.log("文件已保存");
            }
        });
    }
    
    function copyFile(path, filename) {
        readFile(path, filename, function (data) {
            writeFile(path, data, filename);
        });
    }
    

    相关文章

      网友评论

          本文标题:nodejs 复制文件

          本文链接:https://www.haomeiwen.com/subject/aohjmftx.html