本文简要介绍ruby语言中 IO.binread
的用法。
用法
binread(name, [length [, offset]]) → string
binread(name, [length [, offset]]) → string
打开文件,可选择查找给定的 offset
,然后返回 length
字节(默认为文件的其余部分)。 binread 确保文件在返回之前关闭。打开模式将是 "rb:ASCII-8BIT"
。
如果 name
以管道字符 ("|"
) 开头,并且接收者是 IO
类,则以与 Kernel#open
相同的方式创建子进程,并返回其输出。考虑使用 File.binread
来禁用子进程调用的行为。
File.binread("testfile") #=> "This is line one\nThis is line two\nThis is line three\nAnd so on...\n"
File.binread("testfile", 20) #=> "This is line one\nThi"
File.binread("testfile", 20, 10) #=> "ne one\nThis is line "
IO.binread("| cat testfile") #=> "This is line one\nThis is line two\nThis is line three\nAnd so on...\n"
有关name
和open_args 的详细信息,另请参见 IO.read
。
相关用法
- Ruby IO.eof用法及代码示例
- Ruby IO.read用法及代码示例
- Ruby IO.fileno用法及代码示例
- Ruby IO.pread用法及代码示例
- Ruby IO.raw用法及代码示例
- Ruby IO.readlines用法及代码示例
- Ruby IO.to_i用法及代码示例
- Ruby IO.self << object用法及代码示例
- Ruby IO.tty?用法及代码示例
- Ruby IO.close_write用法及代码示例
- Ruby IO.write_nonblock用法及代码示例
- Ruby IO.set_encoding_by_bom用法及代码示例
- Ruby IO.syswrite用法及代码示例
- Ruby IO.close_read用法及代码示例
- Ruby IO.stat用法及代码示例
- Ruby IO.pwrite用法及代码示例
- Ruby IO.ungetc用法及代码示例
- Ruby IO.noecho用法及代码示例
- Ruby IO.new用法及代码示例
- Ruby IO.sysopen用法及代码示例
- Ruby IO.try_convert用法及代码示例
- Ruby IO.write用法及代码示例
- Ruby IO.pathconf用法及代码示例
- Ruby IO.sysseek用法及代码示例
- Ruby IO.closed?用法及代码示例
注:本文由纯净天空筛选整理自ruby-lang.org大神的英文原创作品 IO.binread。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。