るりまサーチ

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

別のキーワード

  1. io popen
  2. io pipe
  3. io readlines
  4. io each_line
  5. io each

ライブラリ

キーワード

検索結果

<< 1 2 3 ... > >>

IO.write(path, string, **opts) -> Integer (27175.0)

path で指定されるファイルを開き、string を書き込み、 閉じます。

...キーワード引数はファイルを開くときに使われ、エンコーディングなどを指定することができます。
詳しくは IO.open を見てください。

@param path ファイル名文字列
@param string 書き込む文字列
@param offset 書き込み開始位置
@par...
...ine three\nAnd so on...\n"
IO
.write("testfile", text) # => 66
IO
.write("testfile", "0123456789", 20) #=> 10
IO
.read("testfile")
# => "This is line one\nThi0123456789two\nThis is line three\nAnd so on...\n"
IO
.write("testfile", "0123456789") #=> 10
IO
.read("testfile")...
...# => "0123456789"
//}

@see IO.binwrite...

IO.write(path, string, offset=nil, **opts) -> Integer (27175.0)

path で指定されるファイルを開き、string を書き込み、 閉じます。

...キーワード引数はファイルを開くときに使われ、エンコーディングなどを指定することができます。
詳しくは IO.open を見てください。

@param path ファイル名文字列
@param string 書き込む文字列
@param offset 書き込み開始位置
@par...
...ine three\nAnd so on...\n"
IO
.write("testfile", text) # => 66
IO
.write("testfile", "0123456789", 20) #=> 10
IO
.read("testfile")
# => "This is line one\nThi0123456789two\nThis is line three\nAnd so on...\n"
IO
.write("testfile", "0123456789") #=> 10
IO
.read("testfile")...
...# => "0123456789"
//}

@see IO.binwrite...

IO#write(*str) -> Integer (27154.0)

IOポートに対して str を出力します。str が文字列でなけ れば to_s による文字列化を試みます。 実際に出力できたバイト数を返します。

...
IO
ポートに対して str を出力します。str が文字列でなけ
れば to_s による文字列化を試みます。
実際に出力できたバイト数を返します。

IO
#syswrite を除く全ての出力メソッドは、最終的に
"write" という名のメソッドを呼び出...
...します。

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

@raise Errno::EXXX 出力に失敗した場合に発生します。

//emlist[例][ruby]{
File.open("textfile", "w+") do |f|
f.write("This is") # => 7
end
File.read("textfile") # => "Th...
...is is"
//}
//emlist[複数引数の例][ruby]{
File.open("textfile", "w+") do |f|
f.write("This is", " a test\n") # => 15
end
File.read("textfile") # => "This is a test\n"
//}...

IO#write(str) -> Integer (27142.0)

IOポートに対して str を出力します。str が文字列でなけ れば to_s による文字列化を試みます。 実際に出力できたバイト数を返します。

...
IO
ポートに対して str を出力します。str が文字列でなけ
れば to_s による文字列化を試みます。
実際に出力できたバイト数を返します。

IO
#syswrite を除く全ての出力メソッドは、最終的に
"write" という名のメソッドを呼び出...
...します。

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

@raise Errno::EXXX 出力に失敗した場合に発生します。

//emlist[例][ruby]{
File.open("textfile", "w+") do |f|
f.write("This is") # => 7
end
File.read("textfile") # => "Th...

IO#close_read -> nil (15170.0)

読み込み用の IO を close します。主にパイプや読み書き両用に作成し た IO オブジェクトで使用します。

...読み込み用の IO を close します。主にパイプや読み書き両用に作成し
IO オブジェクトで使用します。


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

@raise Errno::EXXX close に失敗した場合に発生し...
...ます。

//emlist[例][ruby]{
IO
.popen("/bin/sh","r+") do |f|
f.close_read
# f.readlines # => IOError: not opened for reading
end
//}

@see IO#close, IO#closed?, IO#close_write...
...読み込み用の IO を close します。主にパイプや読み書き両用に作成し
IO オブジェクトで使用します。

既に close されていた場合には単に無視されます。

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

@raise Errno::EXXX close に失敗した場合に発生します。

//emlist[例][ruby]{
IO
.popen("/bin/sh","r+") do |f|
f.close_read
# f.readlines # => IOError: not opened for reading
end
//}

@see IO#close, IO#closed?, IO#close_write...

絞り込み条件を変える

IO#close_write -> nil (15154.0)

書き込み用の IO を close します。

... IO を close します。


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

@raise Errno::EXXX close に失敗した場合に発生します。

//emlist[例][ruby]{
f = IO.popen("/bin/sh","r+") do |f|
f.close_write
# f.print "nowhere" # => IOEr...
...ror: not opened for writing
end
//}

@see IO#close, IO#closed?, IO#close_read...
... IO を close します。

既に close されていた場合には単に無視されます。

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

@raise Errno::EXXX close に失敗した場合に発生します。

//emlist[例][ruby]{
f = IO.popen...
...("/bin/sh","r+") do |f|
f.close_write
# f.print "nowhere" # => IOError: not opened for writing
end
//}

@see IO#close, IO#closed?, IO#close_read...

IO.readlines(path, limit, chomp: false, opts={}) -> [String] (15149.0)

path で指定されたファイルを全て読み込んで、その各行を要素としてもつ配列を返します。

...ist[例][ruby]{
IO
.write("testfile", "line1\nline2,\nline3\n")
IO
.readlines("testfile") # => ["line1\n", "line2,\n", "line3\n"]
IO
.readlines("testfile", ",") # => ["line1\nline2,", "\nline3\n"]
//}

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

IO.readlines(path, rs = $/, chomp: false, opts={}) -> [String] (15149.0)

path で指定されたファイルを全て読み込んで、その各行を要素としてもつ配列を返します。

...ist[例][ruby]{
IO
.write("testfile", "line1\nline2,\nline3\n")
IO
.readlines("testfile") # => ["line1\n", "line2,\n", "line3\n"]
IO
.readlines("testfile", ",") # => ["line1\nline2,", "\nline3\n"]
//}

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

IO.readlines(path, rs, limit, chomp: false, opts={}) -> [String] (15149.0)

path で指定されたファイルを全て読み込んで、その各行を要素としてもつ配列を返します。

...ist[例][ruby]{
IO
.write("testfile", "line1\nline2,\nline3\n")
IO
.readlines("testfile") # => ["line1\n", "line2,\n", "line3\n"]
IO
.readlines("testfile", ",") # => ["line1\nline2,", "\nline3\n"]
//}

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

IO#pread(maxlen, offset, outbuf = "") -> string (15143.0)

preadシステムコールを使ってファイルポインタを変更せずに、また現在のファイルポインタに 依存せずにmaxlenバイト読み込みます。

...preadシステムコールを使ってファイルポインタを変更せずに、また現在のファイルポインタに
依存せずにmaxlenバイト読み込みます。

IO
#seekとIO#readの組み合わせと比べて、アトミックな操作に
なるという点が優れていて、複...
...数スレッド/プロセスから同じIOオブジェクトを
様々な位置から読み込むことを許します。
どのユーザー空間のIO層のバッファリングもバイパスします。

@param maxlen 読み込むバイト数を指定します。
@param offset 読み込み開始...
...ない OS で発生します。

//emlist[例][ruby]{
File.write("testfile", "This is line one\nThis is line two\n")
File.open("testfile") do |f|
p f.read # => "This is line one\nThis is line two\n"
p f.pread(12, 0) # => "This is line"
p f.pread(9, 8) # => "line one\n"
end
//}...

絞り込み条件を変える

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

path で指定したファイルを open し、offset の所まで seek し、 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#pwrite(string, offset) -> Integer (15137.0)

stringをoffsetの位置にpwrite()システムコールを使って書き込みます。

...stringをoffsetの位置にpwrite()システムコールを使って書き込みます。

IO
#seekとIO#writeの組み合わせと比べて、アトミックな操作に
なるという点が優れていて、複数スレッド/プロセスから同じIOオブジェクトを
様々な位置から読...
...み込むことを許します。
どのユーザー空間のIO層のバッファリングもバイパスします。

@param string 書き込む文字列を指定します。
@param offset ファイルポインタを変えずに書き込む位置を指定します。

@return 書き込んだバイ...
...敗した場合に発生します。
@raise NotImplementedError システムコールがサポートされていない OS で発生します。

//emlist[例][ruby]{
File.open("testfile", "w") do |f|
f.pwrite("ABCDEF", 3) # => 6
end

File.read("testfile") # => "\u0000\u0000\u0000ABCDEF"
//}...
<< 1 2 3 ... > >>