从Haxe中的文件读取行 [英] Reading lines from a file in Haxe
本文介绍了从Haxe中的文件读取行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在Haxe中,是否有任何跨语言方法可用于从文件中读取行(适用于所有Haxe目标语言?)
In Haxe, is there any cross-language method for reading lines from a file (that works with all Haxe target languages?)
这是我要实现的方法存根:
Here's the method stub that I'm trying to implement:
static function readLine(fileName, lineNumber){
//now how can I get this method to work with all Haxe target languages?
}
也许可以在Sys类中找到一个相关的方法,但是我还没有找到它.
It might be possible to find a relevant method in the Sys class, but I haven't yet found it.
推荐答案
static function readLine(fileName, lineNumber) {
var fin = sys.io.File.read(fileName, false);
try {
for (i in 0...lineNumber)
fin.readLine();
var line = fin.readLine();
fin.close();
} catch (e:haxe.io.Eof) { return null; }
return line;
}
您正在寻找
http://haxe.org/api/sys/io/file
http://haxe.org/doc/neko/fileio 作为示例.
这篇关于从Haxe中的文件读取行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文