Hi
Thank for your help.
I’m used this code for write time data with your function but i can not find txt file (myTest.txt) in my device.
–
– function
function io.exists( fileName, base )
local base = base or system.DocumentsDirectory
local fileName = fileName
if( base ) then
fileName = system.pathForFile( fileName, base )
end
if not fileName then return false end
local f=io.open(fileName,“r”)
if (f == nil) then
return false
end
io.close(f)
return true
end
if( io.readFile ) then
print(“ERROR! io.readFile() exists already”)
else
function io.readFile( fileName, base )
local base = base or system.DocumentsDirectory
local fileContents
if( io.exists( fileName, base ) == false ) then
return nil
end
local fileName = fileName
if( base ) then
fileName = system.pathForFile( fileName, base )
end
local f=io.open(fileName,“r”)
if (f == nil) then
return nil
end
fileContents = f:read( “*a” )
io.close(f)
return fileContents
end
end
if( io.writeFile ) then
print(“ERROR! io.writeFile() exists already”)
else
function io.writeFile( dataToWrite, fileName, base )
local base = base or system.DocumentsDirectory
local fileName = fileName
if( base ) then
fileName = system.pathForFile( fileName, base )
end
local f=io.open(fileName,“a+”)
if (f == nil) then
return nil
end
f:write( dataToWrite )
io.close(f)
end
end
if( io.appendFile ) then
print(“ERROR! io.appendFile() exists already”)
else
function io.appendFile( dataToWrite, fileName, base )
local base = base or system.DocumentsDirectory
local fileName = fileName
if( base ) then
fileName = system.pathForFile( fileName, base )
end
local f=io.open(fileName,“a”)
if (f == nil) then
return nil
end
f:write( dataToWrite )
io.close(f)
end
end
if( io.readFileTable ) then
print(“ERROR! io.readFileTable() exists already”)
else
function io.readFileTable( fileName, base )
local base = base or system.DocumentsDirectory
local fileContents = {}
if( io.exists( fileName, base ) == false ) then
return fileContents
end
local fileName = fileName
if( base ) then
fileName = system.pathForFile( fileName, base )
end
local f=io.open(fileName,“r”)
if (f == nil) then
return fileContents
end
for line in f:lines() do
fileContents[#fileContents + 1] = line
end
io.close( f )
return fileContents
end
end
display.newText( “time”, 50, 200, native.systemFont, 16 )
local timesa= display.newText( “-”, 300, 200, native.systemFont, 16 )
local timeda= display.newText( “-”, 250, 200, native.systemFont, 16 )
local timeho= display.newText( “-”, 200, 200, native.systemFont, 16 )
local function updateTime()
local time = os.date("*t")
timeho.text=time.hour
timeda.text=time.min
timesa.text=time.sec
io.writeFile( time.hour, “myTest.txt” )
io.writeFile( time.min, “myTest.txt” )
io.writeFile( time.sec, “myTest.txt” )
end
local clockTimer = timer.performWithDelay( 1000, updateTime, -1 )