Spoiler
It wont write more than one note and once you do write more than one the view does not return any notes.
[LUA] Help with reading fs files.
Started by BabyCodder, Apr 02 2013 04:28 AM
9 replies to this topic
#1
Posted 02 April 2013 - 04:28 AM
I need the following program to read all the data and print it: Im not sure why its not working.
#2
Posted 02 April 2013 - 04:31 AM
Edit2: Try doing print(line) in FOR loop ending when line equals nil
Edit: derp...
Edit: derp...
#4
Posted 02 April 2013 - 04:38 AM
Fs Library:
IO Library:
EDIT: Remember to close your file handles
local handle = fs.open(yourFileName,"r") local lines = handle.readLine() for lines in handle.readLine do print(lines) end handle.close()
IO Library:
local handle = io.open("test","r")
local lines = handle:lines()
for lines in handle:lines() do
print(lines)
end
handle:close()
EDIT: Remember to close your file handles
#5
Posted 02 April 2013 - 04:41 AM
SuicidalSTDz, on 02 April 2013 - 04:38 AM, said:
Fs Library:
IO Library:
local handle = fs.open(yourFileName,"r") local lines = handle.readLine() for lines in handle.readLine do print(lines) end
IO Library:
local handle = io.open("test","r")
local lines = handle:lines()
for lines in handle:lines() do
print(lines)
end#6
Posted 02 April 2013 - 04:42 AM
It is my pleasure
#7
Posted 02 April 2013 - 05:11 AM
SuicidalSTDz, on 02 April 2013 - 04:38 AM, said:
Fs Library:
IO Library:
EDIT: Remember to close your file handles
local handle = fs.open(yourFileName,"r") local lines = handle.readLine() for lines in handle.readLine do print(lines) end handle.close()
IO Library:
local handle = io.open("test","r")
local lines = handle:lines()
for lines in handle:lines() do
print(lines)
end
handle:close()
EDIT: Remember to close your file handles
The view does not work. it does not print anything however just looks for another input.
#8
Posted 02 April 2013 - 05:22 AM
The what? Both of these script should work (You have to change the fileName of course)
EDIT: Just tested, these scripts both work flawlessly. Check the file name and make sure it exists on your computer.
EDIT: Just tested, these scripts both work flawlessly. Check the file name and make sure it exists on your computer.
#9
Posted 02 April 2013 - 05:33 AM
It gives me a error on line 55 of the following code:
It's the "for handle in handle.readLine do"
Spoiler
It's the "for handle in handle.readLine do"
#10
Posted 02 April 2013 - 05:40 AM
You are closing the file handle inside the for loop that uses the file contents:
Close it afterward
handle = fs.open("myNotes/notes", "r")
lines = handle.readLine()
for lines in handle.readLine do
print("")
print("notes:")
print(lines)
handle.close()
print("Please Re-Type Command To Continue")
end
Close it afterward
handle = fs.open("myNotes/notes", "r")
lines = handle.readLine()
for lines in handle.readLine do
print("")
print("notes:")
print(lines)
print("Please Re-Type Command To Continue")
end
handle.close()
1 user(s) are reading this topic
0 members, 1 guests, 0 anonymous users











