Total Pageviews

Friday, April 4, 2014

មើល IO ម្តង២ មើល IO.tmpfile () & IO.type()

io.tmpfile()
បើចង់បើក file temporary សំរាប់អានហើយនឹង​ សរសេរ ហើយត្រឡប់ជា handle to it។ នៅពេលដែលកម្មវិធីត្រូវបានបញ្ចប់ ហ្វាល់នឹងត្រូវលុប។
ចំណាំះ io.tmpfile មើលទៅហាក់ដូចជា return nil នៅលើ android

Syntax: io.tmpfile()


io.type() គេប្រើសំរាប់ពិនិត្យ Obj ដែលវា Valid file handle។ ហើយនឹងត្រឡប់ជា String (ហ្វាល់) បើសិនជា Obj ត្រូវបានបើកហ្វាល់ហេនឌល វានឹងបិទហ្វាល់ បើសិនជា Obj ត្រូវបានបិទ ឬក៏ nil បើសិនជា Obj មិនត្រូវបានហេនឌល។

syntax: io.type (obj)

obj(តំរូវការ) វាជា Obj ដែលត្រូវ tested (file handle)
សូមមើលកូដះ
local fh                -- variable for the file handle
print( io.type( fh ) )  -- prints nil
local path = system.pathForFile( "logo.png", system.ResourceDirectory )
fh = io.open( path )
print( io.type( fh ) ) -- prints "file"
io.close( fh )

print( io.type( fh ) ) -- prints "closed file"

No comments:

Post a Comment