File input/output: Difference between revisions

Added RapidQ
m (Moved to FSO cat)
(Added RapidQ)
Line 829:
import shutil
shutil.copyfile('input.txt', 'output.txt')
 
=={{header|RapidQ}}==
 
File I/O is one of the things where RapidQ differs from standard Basic. RapidQ uses file streams.
 
The first version copies text line by line, as in the ''BASIC'' example.
 
$INCLUDE "rapidq.inc"
DIM File1 AS QFileStream
DIM File2 AS QFileStream
File1.Open("input.txt", fmOpenRead)
File2.Open("output.txt", fmCreate)
WHILE NOT File1.EOF
data$ = File1.ReadLine
File2.WriteLine(data$)
WEND
File1.Close
File2.Close
 
When just copying data, the code can be simplified by using the CopyFrom method.<br />
(The second parameter for CopyFrom is number of bytes to copy, 0 = copy the whole file.)
 
$INCLUDE "rapidq.inc"
DIM File1 AS QFileStream
DIM File2 AS QFileStream
File1.Open("input.txt", fmOpenRead)
File2.Open("output.txt", fmCreate)
File2.CopyFrom(File1, 0)
File1.Close
File2.Close
 
=={{header|Raven}}==
Anonymous user