File input/output: Difference between revisions

m
m (Update Lang example: Fix spelling of Lang)
Line 2,116:
w/o create-file throw r>
begin
pad maxstring84 2 pick read-file throw
?dup while
pad swap 3 pick write-file throw
repeat
Line 2,126:
s" output.txt" s" input.txt" copy-file</syntaxhighlight>
 
Note the use of "2 pick" to get the input file handle and "3 pick" to get the output file handle. Local or global variables could have been used, but in this implementation simple stack manipulation was chosen. Also, only maxstring84 bytes are copied at a time, andas that is the globalmaximum guaranteed size of "pad" the global memory area is used to hold the data. For faster copies, allocating a larger buffer could be advantageous.
 
Also, abort" can be used instead of throw if desired.
5

edits