how to print document?
#1
Posted 05 April 2015 - 03:31 PM
#2
Posted 05 April 2015 - 03:34 PM
YUGATUG, on 05 April 2015 - 03:31 PM, said:
local f = fs.open("file", "r")
local contents = f.readAll()
f.close()
print(contents)
I hope it helps.You might want to take a look at the fs API.
Edited by CrazedProgrammer, 05 April 2015 - 03:42 PM.
#3
Posted 05 April 2015 - 05:56 PM
#4
Posted 05 April 2015 - 06:19 PM
When editing a file, hit ctrl to open the menu, and one of the options should be print
If you want to make a program that prints a file, you'll need to use the printer API (Link in lupus's post above)
#5
Posted 05 April 2015 - 06:44 PM
Edited by YUGATUG, 05 April 2015 - 06:44 PM.
#6
Posted 05 April 2015 - 06:56 PM
pastebin.com/jaYn3F0b
Edited by YUGATUG, 05 April 2015 - 07:16 PM.
#7
Posted 05 April 2015 - 07:00 PM
This should work:
--# Write to file
myDocument = {"yolo"}
myFile = fs.open("myFile.txt", "w")
myFile.writeLine(myDocument[1])
myFile.close()
--# Read file
myFile = fs.open("myFile.txt", "r")
contents = myFile.readAll()
myFile.close()
--# Print file
print(contents)
#8
Posted 05 April 2015 - 07:00 PM
#9
Posted 05 April 2015 - 07:22 PM
HPWebcamAble, on 05 April 2015 - 07:00 PM, said:
This should work:
--# Write to file
myDocument = {"yolo"}
myFile = fs.open("myFile.txt", "w")
myFile.writeLine(myDocument[1])
myFile.close()
--# Read file
myFile = fs.open("myFile.txt", "r")
contents = myFile.readAll()
myFile.close()
--# Print file
print(contents)
That is what he has for the read already...
CrazedProgrammer, on 05 April 2015 - 07:00 PM, said:
No he didn't
#10
Posted 05 April 2015 - 07:26 PM
TechedZombie, on 05 April 2015 - 07:22 PM, said:
HPWebcamAble, on 05 April 2015 - 07:00 PM, said:
This should work:
--# Write to file
myDocument = {"yolo"}
myFile = fs.open("myFile.txt", "w")
myFile.writeLine(myDocument[1])
myFile.close()
--# Read file
myFile = fs.open("myFile.txt", "r")
contents = myFile.readAll()
myFile.close()
--# Print file
print(contents)
That is what he has for the read already...
CrazedProgrammer, on 05 April 2015 - 07:00 PM, said:
No he didn't
#11
Posted 05 April 2015 - 07:28 PM
TechedZombie, on 05 April 2015 - 07:22 PM, said:
This was his original:
myFile, myDocument = fs.open("myDocument", "r"), {}--allows document to be written, i don't know what ", {}" does but someone on the forums said to include it
table.insert(myDocument)--not exactly sure what this does
myDocument.close()--done reading
myFile = fs.open("myDocument", "r")
contents = myDocument.readAll()
print(contents)
No, it isn't the same, notice this line (Second to last):
contents = myDocument.readAll() --# myDocument is the table from above, not the file handle
Edited by HPWebcamAble, 05 April 2015 - 07:29 PM.
#12
Posted 05 April 2015 - 08:26 PM
Another question: If i read from a document, then write to it before executing any other command, do i have to use fs.close()?
#13
Posted 05 April 2015 - 08:32 PM
#14
Posted 05 April 2015 - 09:06 PM
jk, thanks for tip
#15
Posted 06 April 2015 - 07:33 PM
#16
Posted 06 April 2015 - 07:38 PM
[code]
temp = fs.open("example","a")
temp.writeLine("hello")
temp.close()
[code]
This would write to the end of the file.
#17
Posted 06 April 2015 - 07:52 PM
#18
Posted 06 April 2015 - 08:08 PM
#19
Posted 06 April 2015 - 08:11 PM
#20
Posted 06 April 2015 - 08:16 PM
Edited by YUGATUG, 06 April 2015 - 08:28 PM.
1 user(s) are reading this topic
0 members, 1 guests, 0 anonymous users











