已经在云中运行的Web系统必须将.txt文件写入用户登录时提供的计算机的地址。
const fs = require('fs');
fs.writeFile(
'C:\Users\user\Documents\'+'nameAchive.txt', //address provided by the user
// for example :: C:\Users\user\Documents\
'data that writes the system',
error => {
if (error)
console.log(error);
else
console.log('success');
});
而我得到这个错误错误:ENOENT:没有此类文件或目录,请打开“ C:\ Users \ user \ Documents”
请尝试使用:
const fs = require('fs');
const createDir = (dirPath) => {
const path = process.cwd() + dirPath;
fs.mkdir(path, { recurcive: true }, (error) => {
if (error) {
console.log('Error!', error);
} else {
console.log('Directory created!');
}
})
}
const createFile = (filePath, fileContent) => {
fs.writeFile(filePath, fileContent, (error) => {
if (error) {
console.log('Error!', error);
} else {
console.log('File created!');
}
})
}
createDir('/test_dir');
createFile('./test_dir/newfile.txt', 'ololo');