2017-06-16 16 views
0

NodeJSの.csvファイルの末尾にカスタムテキストを追加するにはどうすればよいですか?現在、私はCSVファイルを解析し、あらかじめ定義されたパラメータ(区切り文字、列番号など)に対していくつかの検証を行い、その後はファイルの最後にカスタム行を追加する必要があります。NodeJSのCSVファイルの末尾にカスタムテキストを追加

例:

Col1 Col2 Col3 Col4 
Row1 Row1 Row1 Row1 
Row2 Row2 Row2 Row2 
Row3 Row3 Row3 Row3 

そして最後に、文字を行末を持つカスタムラインがあるはずです。

例:

this is the end of file\n 

答えて

2

あなたが簡単に使用することができappendFile

Asynchronously: 

const fs = require('fs'); 

fs.appendFile('yourfile.csv', 'this is the end of file\n', function (err) { 
    if (err) throw err; 
    console.log('Saved!'); 
}); 

Synchronously: 

const fs = require('fs'); 

fs.appendFileSync('yourfile.csv', 'this is the end of file\n'); 
関連する問題