Ruby 读取二进制文件(图片)

http://www.programgo.com/article/88561662456/

cat readJpgFile.rb
jpg_read_file = File.open("Java程序员之路.jpg","rb")
write_file = File.new("Java程序员之路_copy.jpg","wb")

while true
    begin
        read_file = jpg_read_file.sysread(1) #表示一个字节一个字节的读取
        write_file.syswrite(read_file)
    rescue => e
        puts e.message
        break
    end
end

puts "OK"
jpg_read_file.close
write_file.close

Ruby 读取二进制文件(图片)_第1张图片
Paste_Image.png

你可能感兴趣的:(Ruby 读取二进制文件(图片))