local table = {}
--[[ file looks like
file
other
test
have a function read that and insert into a table like]]--
table = {"file","other","test"} -- this is what table should be
thanks for help in advanced
Easiest Way To Read Data In A File
Started by jay5476, Aug 23 2013 03:23 AM
3 replies to this topic
#1
Posted 23 August 2013 - 03:23 AM
what is the easiest way to insert data from a file after every newline eg.
#2
Posted 23 August 2013 - 03:29 AM
it is quite easy to do this, there are several approaches that people take. This is the approach that I have been taking lately:
The above is one of the easiest methods.
--# the lines in the file
local fileData = {}
--# open the file
local handle = assert(fs.open("some_file", 'r'), "Cannot open file for read")
--# read all the lines from the file using an iterator
for line in handle.readLine do
--# insert the line into the table
table.insert(fileData, line)
end
--# close the file header
handle.close()
The above is one of the easiest methods.
#3
Posted 23 August 2013 - 03:43 AM
derpy me forgot about readLine bean using readAll lately
#4
Posted 23 August 2013 - 04:09 AM
Haha, it's ok, we all have those moments from time to time.
1 user(s) are reading this topic
0 members, 1 guests, 0 anonymous users











