File input/output: Difference between revisions

Added COBOL section. Corrected PL/I and R lang tags.
(Added COBOL section. Corrected PL/I and R lang tags.)
Line 569:
(slurp "filename.txt")
</lang>
 
=={{header|COBOL}}==
===Implementation===
{{works with|OpenCOBOL}}
<lang cobol> IDENTIFICATION DIVISION.
PROGRAM-ID. file-io.
 
ENVIRONMENT DIVISION.
INPUT-OUTPUT SECTION.
FILE-CONTROL.
SELECT in-file ASSIGN "input.txt"
ORGANIZATION LINE SEQUENTIAL.
SELECT OPTIONAL out-file ASSIGN "output.txt"
ORGANIZATION LINE SEQUENTIAL.
 
DATA DIVISION.
FILE SECTION.
FD in-file.
01 in-line PIC X(256).
 
FD out-file.
01 out-line PIC X(256).
PROCEDURE DIVISION.
DECLARATIVES.
in-file-error SECTION.
USE AFTER ERROR ON in-file.
DISPLAY "An error occurred while using input.txt."
GOBACK
.
out-file-error SECTION.
USE AFTER ERROR ON out-file.
DISPLAY "An error occurred while using output.txt."
GOBACK
.
END DECLARATIVES.
 
mainline.
OPEN INPUT in-file
OPEN OUTPUT out-file
 
PERFORM FOREVER
READ in-file
AT END
EXIT PERFORM
END-READ
WRITE out-line FROM in-line
END-PERFORM
 
CLOSE in-file, out-file
.</lang>
 
===Built-in Subroutines===
{{works with|OpenCOBOL}}
{{works with|Visual COBOL}}
<lang cobol>*> Originally from ACUCOBOL-GT
CALL "C$COPY" USING "input.txt", "output.txt", 0</lang>
<lang cobol>*> Originally from Micro Focus COBOL
CALL "CBL_COPY_FILE" USING "input.txt", "output.txt"</lang>
 
=={{header|ColdFusion}}==
Line 1,553 ⟶ 1,613:
 
=={{header|PL/I}}==
<lang PL/Ipli>
declare in file, out file;
 
open file (in) title ('/INPUT.TXT,type(text),recsize(100)') input;
open file (out) title ('/OUTPUT.TXT,type(text),recsize(100') output;
do forever;
get file (in) edit (line) (L);
Line 1,690 ⟶ 1,750:
If files are textual we can use <tt>readLines</tt> ("-1" means "read until the end")
 
<lang Rrsplus>src <- file("input.txt", "r")
dest <- file("output.txt", "w")
 
Line 1,699 ⟶ 1,759:
If the files are not textual but "generic":
 
<lang Rrsplus>src <- file("input.txt", "rb")
dest <- file("output.txt", "wb")
 
Line 1,709 ⟶ 1,769:
Another simpler way is to use <tt>file.copy</tt>
 
<lang Rrsplus>file.copy("input.txt", "output.txt", overwrite = FALSE)</lang>
 
=={{header|Racket}}==
Anonymous user