Vishesh
Vishesh

Reputation: 45

Corona sdk: read a file

I recently started working on corona sdk and am trying to read a file and print it line by line. I searched for codes everywhere but they didn't work... It's important as I'm on an internship and need to get it done as soon as possible.

Here's the code that I used:

local path = system.pathForFile( "Level File Structure.txt", system. ResourceDirectory  )
local file = io.open( path, "r" )

for line in file:lines() do
  print( line )
end
io.close( file )

Upvotes: 0

Views: 2167

Answers (2)

Peach Pellen
Peach Pellen

Reputation: 665

This should work provided the file exists and the path is correct;

local path = "Level File Structure.txt", system.ResourceDirectory

local function printWords()
    local file = io.open(path, "r")
    for lines in file:lines() do
        print (lines)
    end
    io.close(file)
end
printWords()

Upvotes: 2

OnlineCop
OnlineCop

Reputation: 4069

You will probably want to look at this blog which describes how to both read and write the files.

Upvotes: 0

Related Questions