-
Notifications
You must be signed in to change notification settings - Fork 0
/
io.rb
54 lines (41 loc) · 893 Bytes
/
io.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
########################
####read file
file = File.new("testfile","r+")
line = file.gets
#line = file.puts
puts line
file.close
File.open("testfile","r") do |file|
while line = file.gets
puts line
end
end
##############################
###get file,return byte
File.open("testfile","r") do |file|
file.each_byte {
|ch|
putc ch
print ". "
}
end
###############################
###get file,return line
File.open("testfile", "r") do |file|
file.each_line { |line| puts "get #{line.dump}" }
end
=end
######################################
####get file,return array
IO.foreach("testfile") { |line| puts line }
str = IO.read("testfile")
puts str.length
puts str
puts str[0..2]
######################################
##IO about network
require 'socket'
client = TCPSocket.open('127.0.0.1','finger')
client.send("mysql\n", 0)
puts client.readlines
client.close