Sunday, 27 October 2013

Read A Text File in Corona

Reading a text file in corona is very eazy.First get the file path and using the file path read the content in the file. Check the code below.
  display.setStatusBar( display.HiddenStatusBar )
    -- read the file path
local filePath = system.pathForFile( "myFile.txt", system.ResourceDirectory )

local file = filePath, "r" )
if file then
 -- read all contents of file into a string
 local contents = file:read( "*a" )

 print( "The file path is" .. filePath )
 print( contents )
 io.close( file )

Copy and download the code and try your self.


  1. This was a nice and helpful post. Thanks for posting this.Keep doing this in future...