nodejs read/write file

fs.readFile('c:\tmp\helloworld.txt','utf8',function(err,data){console.log(data);})

  

 var token=fs.readFileSync('c:\tmp\toekn.txt','utf8');

  

fs.writeFile('c:\tmp\helloworld.txt', 'Hello World! now, hello again!')

  

fs.exists('c:\tmp\helloworld.txt',function(exists){console.log(exists);})

  

fs.existsSync('c:\tmp\helloworld.txt')

  

http://nodejs.org/api/fs.html#fs_fs_exists_path_callback

https://docs.nodejitsu.com/articles/file-system/how-to-read-files-in-nodejs

原文地址:https://www.cnblogs.com/zyip/p/4146823.html