File input/output: Difference between revisions

Content added Content deleted
m (Mortense moved page File IO to File input/output: Expansion.)
m (Spelling/case, as in <http://en.wikipedia.org/wiki/Input/output>.)
Line 276: Line 276:
<lang autohotkey>FileRead, var, input.txt
<lang autohotkey>FileRead, var, input.txt
FileAppend, %var%, output.txt</lang>
FileAppend, %var%, output.txt</lang>
Method 3: the file can be copied without IO.
Method 3: the file can be copied without I/O.
<lang autohotkey>FileCopy, input.txt, output.txt</lang>
<lang autohotkey>FileCopy, input.txt, output.txt</lang>


Binary IO is possible with [http://www.autohotkey.com/forum/topic4604.html&highlight=binread this] library from Laszlo.
Binary I/O is possible with [http://www.autohotkey.com/forum/topic4604.html&highlight=binread this] library from Laszlo.


=={{header|AWK}}==
=={{header|AWK}}==
Line 406: Line 406:
It uses <code>fgetc</code> to read one character at a time. Each character is visited, even though there's nothing to do with it. Copying bigger blocks of data is much more efficient.
It uses <code>fgetc</code> to read one character at a time. Each character is visited, even though there's nothing to do with it. Copying bigger blocks of data is much more efficient.


The following example addresses those issues. To avoid buffered IO, it uses ''open()'', ''read()'', ''write()'' and ''close()'', which are part of [[POSIX]].
The following example addresses those issues. To avoid buffered I/O, it uses ''open()'', ''read()'', ''write()'' and ''close()'', which are part of [[POSIX]].


{{works with|POSIX}}
{{works with|POSIX}}
Line 1,231: Line 1,231:
}</lang>
}</lang>


This version closes both files after without OS intervention
This version closes both files after without OS intervention.


<lang java>import java.io.*;
<lang java>import java.io.*;
Line 2,061: Line 2,061:
In rexx, filename association is used rather than numeric stream numbers and explicit file opening is not required.
In rexx, filename association is used rather than numeric stream numbers and explicit file opening is not required.


===version 1===
===Version 1===
<lang rexx>/*REXX program to read a file and store the contents into an output file*/
<lang rexx>/*REXX program to read a file and store the contents into an output file*/


Line 2,073: Line 2,073:
end
end
/*stick a fork in it, we're done.*/</lang>
/*stick a fork in it, we're done.*/</lang>
===version 2===
===Version 2===
<lang rexx>/*REXX program to read a file and store the contents into an output file*/
<lang rexx>/*REXX program to read a file and store the contents into an output file*/
/*(same as the 1st example, but is faster because no intermediate step.)*/
/*(same as the 1st example, but is faster because no intermediate step.)*/
Line 2,086: Line 2,086:
/*stick a fork in it, we're done.*/</lang>
/*stick a fork in it, we're done.*/</lang>


===version 3===
===Version 3===
Note that this version is limited to files less than one million bytes (and/or possibly virtual memory).
Note that this version is limited to files less than one million bytes (and/or possibly virtual memory).
<lang rexx>/*REXX program to read a file and write contents to an output file*****
<lang rexx>/*REXX program to read a file and write contents to an output file*****