るりまサーチ

最速Rubyリファレンスマニュアル検索!
426件ヒット [1-100件を表示] (0.039秒)
トップページ > クラス:IO[x] > クエリ:open[x] > クエリ:read[x]

別のキーワード

  1. socket open
  2. _builtin open
  3. csv open
  4. tempfile open
  5. zlib open

ライブラリ

キーワード

検索結果

<< 1 2 3 ... > >>

IO.read(path, **opt) -> String | nil (18176.0)

path で指定されたファイルを offset 位置から length バイト分読み込んで返します。

..."" を返します。例えば、IO.read(空ファイル) は "" を返します。

引数 length が指定された場合はバイナリ読み込みメソッド、そうでない場合はテキスト読み込みメソッドとして
動作します。

Kernel.#open と同様 path の先頭が "|"...
...F まで読み込みます。

@param offset 読み込みを始めるオフセットを整数で指定します。

@param opt ファイル path を open する時に使われるオプションをキーワード引数で指定します。

@raise Errno::EXXX path のオープン、offset 位置へ...
...e

IO
.open のモードを指定します。
"r" で始まる文字列である必要があります。

: :open_args

IO
.open に渡される引数を配列で指定します。

これらの他、 :external_encoding など
IO
.open のオプション引数が指定できます。

@see IO...

IO.read(path, length = nil, **opt) -> String | nil (18176.0)

path で指定されたファイルを offset 位置から length バイト分読み込んで返します。

..."" を返します。例えば、IO.read(空ファイル) は "" を返します。

引数 length が指定された場合はバイナリ読み込みメソッド、そうでない場合はテキスト読み込みメソッドとして
動作します。

Kernel.#open と同様 path の先頭が "|"...
...F まで読み込みます。

@param offset 読み込みを始めるオフセットを整数で指定します。

@param opt ファイル path を open する時に使われるオプションをキーワード引数で指定します。

@raise Errno::EXXX path のオープン、offset 位置へ...
...e

IO
.open のモードを指定します。
"r" で始まる文字列である必要があります。

: :open_args

IO
.open に渡される引数を配列で指定します。

これらの他、 :external_encoding など
IO
.open のオプション引数が指定できます。

@see IO...

IO.read(path, length = nil, offset = 0, **opt) -> String | nil (18176.0)

path で指定されたファイルを offset 位置から length バイト分読み込んで返します。

..."" を返します。例えば、IO.read(空ファイル) は "" を返します。

引数 length が指定された場合はバイナリ読み込みメソッド、そうでない場合はテキスト読み込みメソッドとして
動作します。

Kernel.#open と同様 path の先頭が "|"...
...F まで読み込みます。

@param offset 読み込みを始めるオフセットを整数で指定します。

@param opt ファイル path を open する時に使われるオプションをキーワード引数で指定します。

@raise Errno::EXXX path のオープン、offset 位置へ...
...e

IO
.open のモードを指定します。
"r" で始まる文字列である必要があります。

: :open_args

IO
.open に渡される引数を配列で指定します。

これらの他、 :external_encoding など
IO
.open のオプション引数が指定できます。

@see IO...

IO#read(length = nil, outbuf = "") -> String | nil (18144.0)

length バイト読み込んで、その文字列を返します。

...返します。
ただし、length に nil か 0 が指定されている場合は、空文字列 "" を返します。
例えば、open(空ファイル) {|f| f.read } は "" となります。

@param length 読み込むサイズを整数で指定します。
nil が指定された場...
...全てのデータを読み込んで、その文字列を返します。

@param outbuf 出力用のバッファを文字列で指定します。IO#read は読み込んだ
データをその文字列オブジェクトに上書きして返します。指定し
た文字列...
...

@raise IOError 自身が読み込み用にオープンされていなければ発生します。

@raise Errno::EXXX データの読み込みに失敗した場合に発生します。

@raise ArgumentError length が負の場合に発生します。

第二引数を指定した read の呼び...

IO#readlines(limit, chomp: false) -> [String] (6131.0)

データを全て読み込んで、その各行を要素としてもつ配列を返します。 既に EOF に達していれば空配列 [] を返します。

...@raise IOError 自身が読み込み用にオープンされていなければ発生します。

//emlist[例][ruby]{
IO
.write("testfile", "line1,\nline2,\nline3,\n")
File.open("testfile") { |f| p f.readlines } # => ["line1,\n", "line2,\n", "line3,\n"]
File.open("testfile") { |f| p f.readlines...
...\n", "lin", "e3,", "\n"]
File.open("testfile") { |f| p f.readlines(",") } # => ["line1,", "\nline2,", "\nline3,", "\n"]
//}

//emlist[例: rsを取り除く(chomp = true)][ruby]{
IO
.write("testfile", "line1,\rline2,\r\nline3,\n")
File.open("testfile") { |f| p f.readlines(chomp: true) } # =...
...> ["line1,\rline2,", "line3,"]
File.open("testfile") { |f| p f.readlines("\r", chomp: true) } # => ["line1,", "line2,", "\nline3,\n"]
//}

@see $/, IO#gets...

絞り込み条件を変える

IO#readlines(rs = $/, chomp: false) -> [String] (6131.0)

データを全て読み込んで、その各行を要素としてもつ配列を返します。 既に EOF に達していれば空配列 [] を返します。

...@raise IOError 自身が読み込み用にオープンされていなければ発生します。

//emlist[例][ruby]{
IO
.write("testfile", "line1,\nline2,\nline3,\n")
File.open("testfile") { |f| p f.readlines } # => ["line1,\n", "line2,\n", "line3,\n"]
File.open("testfile") { |f| p f.readlines...
...\n", "lin", "e3,", "\n"]
File.open("testfile") { |f| p f.readlines(",") } # => ["line1,", "\nline2,", "\nline3,", "\n"]
//}

//emlist[例: rsを取り除く(chomp = true)][ruby]{
IO
.write("testfile", "line1,\rline2,\r\nline3,\n")
File.open("testfile") { |f| p f.readlines(chomp: true) } # =...
...> ["line1,\rline2,", "line3,"]
File.open("testfile") { |f| p f.readlines("\r", chomp: true) } # => ["line1,", "line2,", "\nline3,\n"]
//}

@see $/, IO#gets...

IO#readlines(rs, limit, chomp: false) -> [String] (6131.0)

データを全て読み込んで、その各行を要素としてもつ配列を返します。 既に EOF に達していれば空配列 [] を返します。

...@raise IOError 自身が読み込み用にオープンされていなければ発生します。

//emlist[例][ruby]{
IO
.write("testfile", "line1,\nline2,\nline3,\n")
File.open("testfile") { |f| p f.readlines } # => ["line1,\n", "line2,\n", "line3,\n"]
File.open("testfile") { |f| p f.readlines...
...\n", "lin", "e3,", "\n"]
File.open("testfile") { |f| p f.readlines(",") } # => ["line1,", "\nline2,", "\nline3,", "\n"]
//}

//emlist[例: rsを取り除く(chomp = true)][ruby]{
IO
.write("testfile", "line1,\rline2,\r\nline3,\n")
File.open("testfile") { |f| p f.readlines(chomp: true) } # =...
...> ["line1,\rline2,", "line3,"]
File.open("testfile") { |f| p f.readlines("\r", chomp: true) } # => ["line1,", "line2,", "\nline3,\n"]
//}

@see $/, IO#gets...

IO.binread(path, length = nil, offset = 0) -> String | nil (6129.0)

path で指定したファイルを open し、offset の所まで seek し、 length バイト読み込みます。

...path で指定したファイルを open し、offset の所まで seek し、
length バイト読み込みます。

Kernel.#open と同様 path の先頭が "|" ならば、"|" に続くコマンドの出力を読み取ります。

length を省略するとファイルの末尾まで読み込み...
...例][ruby]{
IO
.write("testfile", "This is line one\nThis is line two\nThis is line three\nAnd so on...\n")
IO
.binread("testfile") # => "This is line one\nThis is line two\nThis is line three\nAnd so on...\n"
IO
.binread("testfile", 20) # => "This is line one\nThi"
IO
.binread("testfile...
...", 20, 10) # => "ne one\nThis is line "
//}

@see IO.read...

IO.popen([env = {}, [cmdname, arg0], *args, execopt={}], mode = "r", opt={}) -> IO (6126.0)

サブプロセスを実行し、そのプロセスの標準入出力 との間にパイプラインを確立します。生成したパイプを IO オブジェクトとして返します。

...出力
との間にパイプラインを確立します。生成したパイプを IO オブジェクトとして返します。

p io = IO.popen("cat", "r+") # => #<IO:fd 4>
io
.puts "foo"
io
.close_write
p io.gets # => "foo\n"

サブプロセスを指定する方法は2...
...生成した IO オブジェクトを引数にブ
ロックを実行し、ブロックの実行結果を返します。ブロックの実行後、生成したパイ
プは自動的にクローズされます。

p IO.popen("cat", "r+") {|io|
io
.puts "foo"
io
.close_write
io
.gets
}
#...
...は Kernel.#spawn や IO.new を参照してください。

# nkfプロセスから得られる文字列を EUC-JP と指定する
# IO.new などと共通のオプションが指定できる
IO
.popen("nkf -e filename", external_encoding: "EUC-JP"){|nkf_io|
nkf_io.read
}

これに加...

IO.popen([env = {}, [cmdname, arg0], *args, execopt={}], mode = "r", opt={}) {|f| ... } -> object (6126.0)

サブプロセスを実行し、そのプロセスの標準入出力 との間にパイプラインを確立します。生成したパイプを IO オブジェクトとして返します。

...出力
との間にパイプラインを確立します。生成したパイプを IO オブジェクトとして返します。

p io = IO.popen("cat", "r+") # => #<IO:fd 4>
io
.puts "foo"
io
.close_write
p io.gets # => "foo\n"

サブプロセスを指定する方法は2...
...生成した IO オブジェクトを引数にブ
ロックを実行し、ブロックの実行結果を返します。ブロックの実行後、生成したパイ
プは自動的にクローズされます。

p IO.popen("cat", "r+") {|io|
io
.puts "foo"
io
.close_write
io
.gets
}
#...
...は Kernel.#spawn や IO.new を参照してください。

# nkfプロセスから得られる文字列を EUC-JP と指定する
# IO.new などと共通のオプションが指定できる
IO
.popen("nkf -e filename", external_encoding: "EUC-JP"){|nkf_io|
nkf_io.read
}

これに加...

絞り込み条件を変える

<< 1 2 3 ... > >>