const fs = require('fs');
fs.readFile('/etc/passwd', 'utf-8', (err, data) => {
if (err) throw err;
console.log(data);
});
const fs = require('fs');
fs.writeFile('文件名.txt', 'Node.js中文网', 'utf8', (err)=>{
if (err) throw err;
console.log('写入文件成功了!')
});
const fs = require('fs');
fs.readFile('文件名1.txt', 'utf-8', (err, dataStr) => {
if (err) return console.log('读取文件失败:' + err.message)
fs.writeFile('文件名2.txt', dataStr, (err) => {
if (err) return console.log('写入文件失败了:' + err.message)
console.log('恭喜,复制文件OK')
})
})
const fs = require('fs');
fs.appendFile('文件名.txt', 'Node.js中文网', (err) => {
if (err) return console.log('追加文件失败:' + err.message)
console.log('追加文件成功了!')
})
const fs = require('fs');
fs.stat('文件名.txt', (err, stats) => {
if (err) return console.log('读取信息失败:' + err.message)
console.log(stats)
})
const fs = require('fs');
fs.readdir(__dirname, (err, filenames) => {
if (err) throw err;
console.log(filenames)
})
const path = require('path');
const abspath = path.join(__dirname, '1.txt');
const path = require('path');
path.basename('/foo/bar/baz/asdf/quux.html');
path.basename('/foo/bar/baz/asdf/quux.html', '.html');
path.dirname('/foo/bar/baz/asdf/quux');
path.extname('index.html');
path.extname('index.coffee.md');
path.extname('index.');
path.extname('index');
path.extname('.index');