如何将文件内容复制到另一个文件,但在Javascript中更改它的某些行?

时间:2018-04-04 17:00:26

标签: javascript

我可以获取文件内容并将其拆分,但是如何将第5行更改为其他内容?

你怎么能打电话给线路?结果看起来像这样:

const fs = require("fs)
fs.readFile('./some/path/file.js', 'utf8', function read(err, data) {
    if(err) {
        console.log(err)
    }
    content = data;     

});
var something = \n
var result = content.split(something)
//now ho can i get all the lines before 5 and all the lines after 6?
var 5 = //lines before 6
var 6 = //lines after six
//so i could just do
var final = 5 + \n + result + 6 + \n + result //???
//so it would be a one variable again
console.log("one variable " + final)

0 个答案:

没有答案