3
我正尝试使用Coffeescript读取文件。在我进入coffee
回购站的同一文件夹中,我有一个名为hello.txt
的文件。使用Coffeescript读取本地文件
coffee> fs = require 'fs'
coffee> x = fs.readFile "hello.txt"
undefined
coffee> x
undefined
我在做什么错?
我正尝试使用Coffeescript读取文件。在我进入coffee
回购站的同一文件夹中,我有一个名为hello.txt
的文件。使用Coffeescript读取本地文件
coffee> fs = require 'fs'
coffee> x = fs.readFile "hello.txt"
undefined
coffee> x
undefined
我在做什么错?
你不能传递一个回调readFile
实际读取文件。有关更多信息,请参见docs。通常,由于平台的异步特性,nodejs方法是异步的。对于他们中的一些人来说,有一个同步版本。事实上,您可以使用readFileSync方法读取文件。
噢,非常感谢! – grautur 2012-02-20 23:43:08