else
print("myfile1 did not open for write")
print("error string is " .. myfile1_err)
print("error number is " .. myfile1_errnum)
end
-- Open the three files again for reading.
myfile1, myfile1_err, myfile1_errnum = io.open("/usb1/myfile_io1", "r")
myfile2, myfile2_err, myfile2_errnum = io.open("/usb1/myfile_io2", "r")
myfile3, myfile3_err, myfile3_errnum = io.open("/usb1/myfile_io3", "r")
if (io.type(myfile1) == "file") then
if (io.type(myfile2) == "file") then
if (io.type(myfile3) == "file") then
-- Make myfile1 the default input file.
io.input(myfile1)
-- Read the default file.
filecontents = io.read("*a")
print("contents of myfile1 are:")
print(filecontents)
print()
-- Make myfile2 the default input file.
io.input(myfile2)
-- Read the default file.
filecontents = io.read("*a")
print("contents of myfile2 are:")
print(filecontents)
print()
-- Read myfile3 using file descriptor instead of io read.
filecontents = myfile3:read("*a")
print("contents of myfile3 are:")
print(filecontents)
print()
-- Use file descriptor close command rather than io close.
myfile1:close()
myfile2:close()
myfile3:close()
else
print("myfile3 did not open for read")
print("error string is " .. myfile3_err)
print("error number is " .. myfile3_errnum)
end
else
print("myfile2 did not open for read")
print("error string is " .. myfile2_err)
print("error number is " .. myfile2_errnum)
end
else
print("myfile1 did not open for read")
print("error string is " .. myfile1_err)
print("error number is " .. myfile1_errnum)
end
endscript