Data commit

This commit is contained in:
Ingy döt Net 2023-07-01 11:58:00 -04:00
parent 7387c8f97b
commit cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions

View file

@ -0,0 +1,3 @@
---
from: http://rosettacode.org/wiki/File_input/output
note: File handling

View file

@ -0,0 +1,13 @@
{{selection|Short Circuit|Console Program Basics}} [[Category:Simple]]
;Task:
Create a file called   "output.txt",   and place in it the contents of the file   "input.txt",   ''via an intermediate variable''.
In other words, your program will demonstrate:
::#   how to read from a file into a variable
::#   how to write a variable's contents into a file
<br>
Oneliners that skip the intermediate variable are of secondary interest — operating systems have copy commands for that.
<br><br>

View file

@ -0,0 +1,2 @@
V file_contents = File(input.txt).read()
File(output.txt, w).write(file_contents)

View file

@ -0,0 +1,150 @@
/* ARM assembly AARCH64 Raspberry PI 3B */
/* program readwrtFile64.s */
/*******************************************/
/* Constantes file */
/*******************************************/
/* for this file see task include a file in language AArch64 assembly*/
.include "../includeConstantesARM64.inc"
.equ TAILLEBUF, 1000
/*********************************/
/* Initialized data */
/*********************************/
.data
szMessErreur: .asciz "Error open input file.\n"
szMessErreur4: .asciz "Error open output file.\n"
szMessErreur1: .asciz "Error close file.\n"
szMessErreur2: .asciz "Error read file.\n"
szMessErreur3: .asciz "Error write output file.\n"
/*************************************************/
szMessCodeErr: .asciz "Error code décimal : @ \n"
szNameFileInput: .asciz "input.txt"
szNameFileOutput: .asciz "output.txt"
/*******************************************/
/* UnInitialized data */
/*******************************************/
.bss
sBuffer: .skip TAILLEBUF
sZoneConv: .skip 24
/**********************************************/
/* -- Code section */
/**********************************************/
.text
.global main
main: // entry of program
mov x0,AT_FDCWD
ldr x1,qAdrszNameFileInput // file name
mov x2,#O_RDWR // flags
mov x3,#0 // mode
mov x8,#OPEN // call system OPEN
svc #0
cmp x0,0 // open error ?
ble erreur
mov x19,x0 // save File Descriptor
ldr x1,qAdrsBuffer // buffer address
mov x2,TAILLEBUF // buffer size
mov x8,READ // call system READ
svc 0
cmp x0,0 // read error ?
ble erreur2
mov x20,x0 // length read characters
// close imput file
mov x0,x19 // Fd
mov x8,CLOSE // call system CLOSE
svc 0
cmp x0,0 // close error ?
blt erreur1
// create output file
mov x0,AT_FDCWD
ldr x1,qAdrszNameFileOutput // file name
mov x2,O_CREAT|O_RDWR // flags
ldr x3,qFicMask1 // Mode
mov x8,OPEN // call system open file
svc 0
cmp x0,#0 // create error ?
ble erreur4
mov x19,x0 // file descriptor
ldr x1,qAdrsBuffer
mov x2,x20 // length to write
mov x8, #WRITE // select system call 'write'
svc #0 // perform the system call
cmp x0,#0 // error write ?
blt erreur3
// close output file
mov x0,x19 // Fd fichier
mov x8, #CLOSE // call system CLOSE
svc #0
cmp x0,#0 // error close ?
blt erreur1
mov x0,#0 // return code OK
b 100f
erreur:
ldr x1,qAdrszMessErreur
bl displayError
mov x0,#1 // error return code
b 100f
erreur1:
ldr x1,qAdrszMessErreur1
bl displayError
mov x0,#1 // error return code
b 100f
erreur2:
ldr x1,qAdrszMessErreur2
bl displayError
mov x0,#1 // error return code
b 100f
erreur3:
ldr x1,qAdrszMessErreur3
bl displayError
mov x0,#1 // error return code
b 100f
erreur4:
ldr x1,qAdrszMessErreur4
bl displayError
mov x0,#1 // error return code
b 100f
100: // end program
mov x8,EXIT
svc 0
qAdrszNameFileInput: .quad szNameFileInput
qAdrszNameFileOutput: .quad szNameFileOutput
qAdrszMessErreur: .quad szMessErreur
qAdrszMessErreur1: .quad szMessErreur1
qAdrszMessErreur2: .quad szMessErreur2
qAdrszMessErreur3: .quad szMessErreur3
qAdrszMessErreur4: .quad szMessErreur4
qAdrsBuffer: .quad sBuffer
qFicMask1: .quad 0644
/******************************************************************/
/* display error message */
/******************************************************************/
/* x0 contains error code */
/* x1 contains address error message */
displayError:
stp x2,lr,[sp,-16]! // save registers
mov x2,x0 // save error code
mov x0,x1 // display message error
bl affichageMess
mov x0,x2
ldr x1,qAdrsZoneConv // conversion error code
bl conversion10S // decimal conversion
ldr x0,qAdrszMessCodeErr
ldr x1,qAdrsZoneConv
bl strInsertAtCharInc // insert result at @ character
bl affichageMess // display message final
ldp x2,lr,[sp],16 // restaur 2 registers
ret // return to address lr x30
qAdrsZoneConv: .quad sZoneConv
qAdrszMessCodeErr: .quad szMessCodeErr
/********************************************************/
/* File Include fonctions */
/********************************************************/
/* for this file see task include a file in language AArch64 assembly */
.include "../includeARM64.inc"

View file

@ -0,0 +1,39 @@
:set-state-ok t
(defun read-channel (channel limit state)
(mv-let (ch state)
(read-char$ channel state)
(if (or (null ch)
(zp limit))
(let ((state (close-input-channel channel state)))
(mv nil state))
(mv-let (so-far state)
(read-channel channel (1- limit) state)
(mv (cons ch so-far) state)))))
(defun read-from-file (filename limit state)
(mv-let (channel state)
(open-input-channel filename :character state)
(mv-let (contents state)
(read-channel channel limit state)
(mv (coerce contents 'string) state))))
(defun write-channel (channel cs state)
(if (endp cs)
(close-output-channel channel state)
(let ((state (write-byte$ (char-code (first cs))
channel state)))
(let ((state (write-channel channel
(rest cs)
state)))
state))))
(defun write-to-file (filename str state)
(mv-let (channel state)
(open-output-channel filename :byte state)
(write-channel channel (coerce str 'list) state)))
(defun copy-file (in out state)
(mv-let (contents state)
(read-from-file in (expt 2 40) state)
(write-to-file out contents state)))

View file

@ -0,0 +1,46 @@
PROC copy file v1 = (STRING in name, out name)VOID: (
# note: algol68toc-1.18 - can compile, but not run v1 #
INT errno;
FILE in file, out file;
errno := open(in file, in name, stand in channel);
errno := open(out file, out name, stand out channel);
BOOL in ended := FALSE;
PROC call back ended = (REF FILE f) BOOL: in ended := TRUE;
on logical file end(in file, call back ended);
STRING line;
WHILE
get(in file, (line, new line));
# WHILE # NOT in ended DO # break to avoid excess new line #
put(out file, (line, new line))
OD;
ended:
close(in file);
close(out file)
);
PROC copy file v2 = (STRING in name, out name)VOID: (
INT errno;
FILE in file, out file;
errno := open(in file, in name, stand in channel);
errno := open(out file, out name, stand out channel);
PROC call back ended = (REF FILE f) BOOL: GO TO done;
on logical file end(in file, call back ended);
STRING line;
DO
get(in file, line);
put(out file, line);
get(in file, new line);
put(out file, new line)
OD;
done:
close(in file);
close(out file)
);
test:(
copy file v2("input.txt","output.txt")
)

View file

@ -0,0 +1,225 @@
/* ARM assembly Raspberry PI */
/* program readwrtfile.s */
/*********************************************/
/*constantes */
/********************************************/
.equ STDOUT, 1 @ Linux output console
.equ EXIT, 1 @ Linux syscall
.equ READ, 3
.equ WRITE, 4
.equ OPEN, 5
.equ CLOSE, 6
.equ CREATE, 8
/* file */
.equ O_RDWR, 0x0002 @ open for reading and writing
.equ TAILLEBUF, 1000
/*********************************/
/* Initialized data */
/*********************************/
.data
szMessErreur: .asciz "Erreur ouverture fichier input.\n"
szMessErreur4: .asciz "Erreur création fichier output.\n"
szMessErreur1: .asciz "Erreur fermeture fichier.\n"
szMessErreur2: .asciz "Erreur lecture fichier.\n"
szMessErreur3: .asciz "Erreur d'écriture dans fichier de sortie.\n"
szRetourligne: .asciz "\n"
szMessErr: .ascii "Error code : "
sDeci: .space 15,' '
.asciz "\n"
szNameFileInput: .asciz "input.txt"
szNameFileOutput: .asciz "output.txt"
/*******************************************/
/* DONNEES NON INITIALISEES */
/*******************************************/
.bss
sBuffer: .skip TAILLEBUF
/**********************************************/
/* -- Code section */
/**********************************************/
.text
.global main
main:
push {fp,lr} /* save registers */
ldr r0,iAdrszNameFileInput @ file name
mov r1,#O_RDWR @ flags
mov r2,#0 @ mode
mov r7,#OPEN @ call system OPEN
swi #0
cmp r0,#0 @ open error ?
ble erreur
mov r8,r0 @ save File Descriptor
ldr r1,iAdrsBuffer @ buffer address
mov r2,#TAILLEBUF @ buffer size
mov r7, #READ @ call system READ
swi 0
cmp r0,#0 @ read error ?
ble erreur2
mov r2,r0 @ length read characters
/* close imput file */
mov r0,r8 @ Fd
mov r7, #CLOSE @ call system CLOSE
swi 0
cmp r0,#0 @ close error ?
blt erreur1
@ create output file
ldr r0,iAdrszNameFileOutput @ file name
ldr r1,iFicMask1 @ flags
mov r7, #CREATE @ call system create file
swi 0
cmp r0,#0 @ create error ?
ble erreur4
mov r0,r8 @ file descriptor
ldr r1,iAdrsBuffer
@ et r2 contains the length to write
mov r7, #WRITE @ select system call 'write'
swi #0 @ perform the system call
cmp r0,#0 @ error write ?
blt erreur3
@ close output file
mov r0,r8 @ Fd fichier
mov r7, #CLOSE @ call system CLOSE
swi #0
cmp r0,#0 @ error close ?
blt erreur1
mov r0,#0 @ return code OK
b 100f
erreur:
ldr r1,iAdrszMessErreur
bl afficheerreur
mov r0,#1 @ error return code
b 100f
erreur1:
ldr r1,iAdrszMessErreur1
bl afficheerreur
mov r0,#1 @ error return code
b 100f
erreur2:
ldr r1,iAdrszMessErreur2
bl afficheerreur
mov r0,#1 @ error return code
b 100f
erreur3:
ldr r1,iAdrszMessErreur3
bl afficheerreur
mov r0,#1 @ error return code
b 100f
erreur4:
ldr r1,iAdrszMessErreur4
bl afficheerreur
mov r0,#1 @ error return code
b 100f
100: @ end program
pop {fp,lr} /* restaur des 2 registres */
mov r7, #EXIT /* appel fonction systeme pour terminer */
swi 0
iAdrszNameFileInput: .int szNameFileInput
iAdrszNameFileOutput: .int szNameFileOutput
iAdrszMessErreur: .int szMessErreur
iAdrszMessErreur1: .int szMessErreur1
iAdrszMessErreur2: .int szMessErreur2
iAdrszMessErreur3: .int szMessErreur3
iAdrszMessErreur4: .int szMessErreur4
iAdrsBuffer: .int sBuffer
iFicMask1: .octa 0644
/******************************************************************/
/* display text with size calculation */
/******************************************************************/
/* r0 contains the address of the message */
affichageMess:
push {r0,r1,r2,r7,lr} /* save registres */
mov r2,#0 /* counter length */
1: /* loop length calculation */
ldrb r1,[r0,r2] /* read octet start position + index */
cmp r1,#0 /* if 0 its over */
addne r2,r2,#1 /* else add 1 in the length */
bne 1b /* and loop */
/* so here r2 contains the length of the message */
mov r1,r0 /* address message in r1 */
mov r0,#STDOUT /* code to write to the standard output Linux */
mov r7, #WRITE /* code call system "write" */
swi #0 /* call systeme */
pop {r0,r1,r2,r7,lr} /* restaur des 2 registres */
bx lr /* return */
/***************************************************/
/* display error message */
/***************************************************/
/* r0 contains error code r1 address error message */
afficheerreur:
push {r1-r2,lr} @ save registers
mov r2,r0 @ save error code
mov r0,r1 @ address error message
bl affichageMess @ display error message
mov r0,r2 @ error code
ldr r1,iAdrsDeci @ result address
bl conversion10S
ldr r0,iAdrszMessErr @ display error code
bl affichageMess
pop {r1-r2,lr} @ restaur registers
bx lr @ return function
iAdrszMessErr: .int szMessErr
iAdrsDeci: .int sDeci
/***************************************************/
/* Converting a register to a signed decimal */
/***************************************************/
/* r0 contains value and r1 area address */
conversion10S:
push {r0-r4,lr} @ save registers
mov r2,r1 /* debut zone stockage */
mov r3,#'+' /* par defaut le signe est + */
cmp r0,#0 @ negative number ?
movlt r3,#'-' @ yes
mvnlt r0,r0 @ number inversion
addlt r0,#1
mov r4,#10 @ length area
1: @ start loop
bl divisionPar10R
add r1,#48 @ digit
strb r1,[r2,r4] @ store digit on area
sub r4,r4,#1 @ previous position
cmp r0,#0 @ stop if quotient = 0
bne 1b
strb r3,[r2,r4] @ store signe
subs r4,r4,#1 @ previous position
blt 100f @ if r4 < 0 -> end
mov r1,#' ' @ space
2:
strb r1,[r2,r4] @store byte space
subs r4,r4,#1 @ previous position
bge 2b @ loop if r4 > 0
100:
pop {r0-r4,lr} @ restaur registers
bx lr
/***************************************************/
/* division for 10 fast unsigned */
/***************************************************/
@ r0 contient le dividende
@ r0 retourne le quotient
@ r1 retourne le reste
divisionPar10R:
push {r2,lr} @ save registers
sub r1, r0, #10 @ calcul de r0 - 10
sub r0, r0, r0, lsr #2 @ calcul de r0 - (r0 /4)
add r0, r0, r0, lsr #4 @ calcul de (r0-(r0/4))+ ((r0-(r0/4))/16
add r0, r0, r0, lsr #8 @ etc ...
add r0, r0, r0, lsr #16
mov r0, r0, lsr #3
add r2, r0, r0, asl #2
subs r1, r1, r2, asl #1 @ calcul (N-10) - (N/10)*10
addpl r0, r0, #1 @ regul quotient
addmi r1, r1, #10 @ regul reste
pop {r2,lr}
bx lr

View file

@ -0,0 +1,5 @@
BEGIN {
while ( (getline <"input.txt") > 0 ) {
print >"output.txt"
}
}

View file

@ -0,0 +1,56 @@
INCLUDE "D2:IO.ACT" ;from the Action! Tool Kit
PROC Dir(CHAR ARRAY filter)
BYTE dev=[1]
CHAR ARRAY line(255)
Close(dev)
Open(dev,filter,6)
DO
InputSD(dev,line)
PrintE(line)
IF line(0)=0 THEN
EXIT
FI
OD
Close(dev)
RETURN
PROC CopyFile(CHAR ARRAY src,dst)
DEFINE BUF_LEN="1000"
BYTE in=[1], out=[2]
BYTE ARRAY buff(BUF_LEN)
CARD len
Close(in)
Close(out)
Open(in,src,4)
Open(out,dst,8)
DO
len=Bget(in,buff,BUF_LEN)
IF len>0 THEN
Bput(out,buff,len)
FI
UNTIL len#BUF_LEN
OD
Close(in)
Close(out)
RETURN
PROC Main()
CHAR ARRAY filter="D:*.*",
src="D:INPUT.TXT", dst="D:OUTPUT.TXT"
Put(125) PutE() ;clear screen
PrintF("Dir ""%S""%E",filter)
Dir(filter)
PrintF("Copy ""%S"" to ""%S""%E%E",src,dst)
CopyFile(src,dst)
PrintF("Dir ""%S""%E",filter)
Dir(filter)
RETURN

View file

@ -0,0 +1,30 @@
with Ada.Text_IO; use Ada.Text_IO;
procedure Read_And_Write_File_Line_By_Line is
Input, Output : File_Type;
begin
Open (File => Input,
Mode => In_File,
Name => "input.txt");
Create (File => Output,
Mode => Out_File,
Name => "output.txt");
loop
declare
Line : String := Get_Line (Input);
begin
-- You can process the contents of Line here.
Put_Line (Output, Line);
end;
end loop;
Close (Input);
Close (Output);
exception
when End_Error =>
if Is_Open(Input) then
Close (Input);
end if;
if Is_Open(Output) then
Close (Output);
end if;
end Read_And_Write_File_Line_By_Line;

View file

@ -0,0 +1,51 @@
with Ada.Command_Line, Ada.Text_IO; use Ada.Command_Line, Ada.Text_IO;
procedure Read_And_Write_File_Line_By_Line is
Read_From : constant String := "input.txt";
Write_To : constant String := "output.txt";
Input, Output : File_Type;
begin
begin
Open (File => Input,
Mode => In_File,
Name => Read_From);
exception
when others =>
Put_Line (Standard_Error,
"Can not open the file '" & Read_From & "'. Does it exist?");
Set_Exit_Status (Failure);
return;
end;
begin
Create (File => Output,
Mode => Out_File,
Name => Write_To);
exception
when others =>
Put_Line (Standard_Error,
"Can not create a file named '" & Write_To & "'.");
Set_Exit_Status (Failure);
return;
end;
loop
declare
Line : String := Get_Line (Input);
begin
-- You can process the contents of Line here.
Put_Line (Output, Line);
end;
end loop;
Close (Input);
Close (Output);
exception
when End_Error =>
if Is_Open(Input) then
Close (Input);
end if;
if Is_Open(Output) then
Close (Output);
end if;
end Read_And_Write_File_Line_By_Line;

View file

@ -0,0 +1,26 @@
with Ada.Sequential_IO;
procedure Read_And_Write_File_Character_By_Character is
package Char_IO is new Ada.Sequential_IO (Character);
use Char_IO;
Input, Output : File_Type;
Buffer : Character;
begin
Open (File => Input, Mode => In_File, Name => "input.txt");
Create (File => Output, Mode => Out_File, Name => "output.txt");
loop
Read (File => Input, Item => Buffer);
Write (File => Output, Item => Buffer);
end loop;
Close (Input);
Close (Output);
exception
when End_Error =>
if Is_Open(Input) then
Close (Input);
end if;
if Is_Open(Output) then
Close (Output);
end if;
end Read_And_Write_File_Character_By_Character;

View file

@ -0,0 +1,24 @@
with Ada.Text_IO; use Ada.Text_IO;
with Ada.Text_IO.Text_Streams; use Ada.Text_IO.Text_Streams;
procedure Using_Text_Streams is
Input, Output : File_Type;
Buffer : Character;
begin
Open (File => Input, Mode => In_File, Name => "input.txt");
Create (File => Output, Mode => Out_File, Name => "output.txt");
loop
Buffer := Character'Input (Stream (Input));
Character'Write (Stream (Output), Buffer);
end loop;
Close (Input);
Close (Output);
exception
when End_Error =>
if Is_Open(Input) then
Close (Input);
end if;
if Is_Open(Output) then
Close (Output);
end if;
end Using_Text_Streams;

View file

@ -0,0 +1,11 @@
file i, o;
text s;
i.open("input.txt", OPEN_READONLY, 0);
o.open("output.txt", OPEN_CREATE | OPEN_TRUNCATE | OPEN_WRITEONLY,
0644);
while (i.line(s) ^ -1) {
o.text(s);
o.byte('\n');
}

View file

@ -0,0 +1,8 @@
on copyFile from src into dst
set filedata to read file src
set outfile to open for access dst with write permission
write filedata to outfile
close access outfile
end copyFile
copyFile from ":input.txt" into ":output.txt"

View file

@ -0,0 +1,24 @@
100 I$ = "INPUT.TXT"
110 O$ = "OUTPUT.TXT"
120 M$ = CHR$(13)
130 D$ = CHR$(4)
140 PRINT D$"VERIFY"I$
150 PRINT D$"OPEN"O$
160 PRINT D$"DELETE"O$
170 PRINT D$"OPEN"O$
180 PRINT D$"OPEN"I$
190 PRINT D$"READ"I$
200 ONERR GOTO 280
210 GET C$
220 POKE 216,0
230 PRINT M$D$"WRITE"O$",B"B
240 B = B + 1
250 P = 2 - (C$ <> M$)
260 PRINT MID$(C$, P)
270 GOTO 190
280 POKE 216,0
290 EOF = PEEK(222) = 5
300 IF NOT EOF THEN RESUME
310 PRINT M$D$"CLOSE"

View file

@ -0,0 +1,4 @@
source: read "input.txt"
write "output.txt" source
print source

View file

@ -0,0 +1,2 @@
Loop, Read, input.txt, output.txt
FileAppend, %A_LoopReadLine%`n

View file

@ -0,0 +1,2 @@
FileRead, var, input.txt
FileAppend, %var%, output.txt

View file

@ -0,0 +1 @@
FileCopy, input.txt, output.txt

View file

@ -0,0 +1,8 @@
open 1, "input.txt"
open 2, "output.txt"
while not eof(1)
linea$ = readline(1)
write 2, linea$
end while
close 1
close 2

View file

@ -0,0 +1 @@
*COPY input.txt output.txt

View file

@ -0,0 +1,7 @@
infile% = OPENIN("input.txt")
outfile% = OPENOUT("output.txt")
WHILE NOT EOF#infile%
BPUT #outfile%, BGET#infile%
ENDWHILE
CLOSE #infile%
CLOSE #outfile%

View file

@ -0,0 +1,34 @@
GET "libhdr"
LET start() BE $(
// Attempt to open the named files.
LET source = findinput("input.txt")
LET destination = findoutput("output.txt")
TEST source = 0 THEN
writes("Unable to open input.txt*N")
ELSE TEST destination = 0 THEN
writes("Unable to open output.txt*N")
ELSE $(
// The current character, initially unknown.
LET ch = ?
// Make the open files the current input and output streams.
selectinput(source)
selectoutput(destination)
// Copy the input to the output character by character until
// endstreamch is returned to indicate input is exhausted.
ch := rdch()
UNTIL ch = endstreamch DO $(
wrch(ch)
ch := rdch()
$)
// Close the currently selected streams.
endread()
endwrite()
$)
$)

View file

@ -0,0 +1,2 @@
data•FBytes "input.txt"
"output.txt" •FBytes data

View file

@ -0,0 +1,2 @@
text$ = LOAD$("input.txt")
SAVE text$ TO "output.txt"

View file

@ -0,0 +1,4 @@
(main
{ "input.txt" >>> -- File is now on stack
foo set -- File is now in 'foo'
foo "output.txt" <<< })

View file

@ -0,0 +1 @@
copy input.txt output.txt

View file

@ -0,0 +1 @@
type input.txt > output.txt

View file

@ -0,0 +1 @@
for /f "" %L in ('more^<input.txt') do echo %L>>output.txt

View file

@ -0,0 +1,15 @@
using System;
using System.IO;
namespace FileIO
{
class Program
{
static void Main()
{
String s = scope .();
File.ReadAllText("input.txt", s);
File.WriteAllText("output.txt", s);
}
}
}

View file

@ -0,0 +1 @@
0110"txt.tupni"#@i10"txt.tuptuo"#@o@

View file

@ -0,0 +1 @@
put$(get$"input.txt","output.txt",NEW)

View file

@ -0,0 +1,28 @@
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
int main() {
string line;
ifstream input ( "input.txt" );
ofstream output ("output.txt");
if (output.is_open()) {
if (input.is_open()){
while (getline (input,line)) {
output << line << endl;
}
input.close(); // Not necessary - will be closed when variable goes out of scope.
}
else {
cout << "input.txt cannot be opened!\n";
}
output.close(); // Not necessary - will be closed when variable goes out of scope.
}
else {
cout << "output.txt cannot be written to!\n";
}
return 0;
}

View file

@ -0,0 +1,29 @@
#include <iostream>
#include <fstream>
#include <cstdlib>
int main()
{
std::ifstream input("input.txt");
if (!input.is_open())
{
std::cerr << "could not open input.txt for reading.\n";
return EXIT_FAILURE;
}
std::ofstream output("output.txt");
if (!output.is_open())
{
std::cerr << "could not open output.txt for writing.\n";
return EXIT_FAILURE;
}
output << input.rdbuf();
if (!output)
{
std::cerr << "error copying the data.\n";
return EXIT_FAILURE;
}
return EXIT_SUCCESS;
}

View file

@ -0,0 +1,10 @@
# include <algorithm>
# include <fstream>
int main() {
std::ifstream ifile("input.txt");
std::ofstream ofile("output.txt");
std::copy(std::istreambuf_iterator<char>(ifile),
std::istreambuf_iterator<char>(),
std::ostreambuf_iterator<char>(ofile));
}

View file

@ -0,0 +1,8 @@
#include <fstream>
int main()
{
std::ifstream input("input.txt");
std::ofstream output("output.txt");
output << input.rdbuf();
}

View file

@ -0,0 +1,8 @@
using System.IO;
using (var reader = new StreamReader("input.txt"))
using (var writer = new StreamWriter("output.txt"))
{
var text = reader.ReadToEnd();
writer.Write(text);
}

View file

@ -0,0 +1,4 @@
using System.IO;
var text = File.ReadAllText("input.txt");
File.WriteAllText("output.txt", text);

View file

@ -0,0 +1,27 @@
#include <stdio.h>
int main(int argc, char **argv) {
FILE *in, *out;
int c;
in = fopen("input.txt", "r");
if (!in) {
fprintf(stderr, "Error opening input.txt for reading.\n");
return 1;
}
out = fopen("output.txt", "w");
if (!out) {
fprintf(stderr, "Error opening output.txt for writing.\n");
fclose(in);
return 1;
}
while ((c = fgetc(in)) != EOF) {
fputc(c, out);
}
fclose(out);
fclose(in);
return 0;
}

View file

@ -0,0 +1,36 @@
#include <unistd.h>
#include <fcntl.h>
#include <sys/types.h>
#include <sys/stat.h>
/* we just return a yes/no status; caller can check errno */
int copy_file(const char *in, const char *out)
{
int ret = 0;
int fin, fout;
ssize_t len;
char *buf[4096]; /* buffer size, some multiple of block size preferred */
struct stat st;
if ((fin = open(in, O_RDONLY)) == -1) return 0;
if (fstat(fin, &st)) goto bail;
/* open output with same permission */
fout = open(out, O_WRONLY|O_CREAT|O_TRUNC, st.st_mode & 0777);
if (fout == -1) goto bail;
while ((len = read(fin, buf, 4096)) > 0)
write(fout, buf, len);
ret = len ? 0 : 1; /* last read should be 0 */
bail: if (fin != -1) close(fin);
if (fout != -1) close(fout);
return ret;
}
int main()
{
copy_file("infile", "outfile");
return 0;
}

View file

@ -0,0 +1,23 @@
int copy_file(const char *in, const char *out)
{
int ret = 0;
int fin, fout;
char *bi;
struct stat st;
if ((fin = open(in, O_RDONLY)) == -1) return 0;
if (fstat(fin, &st)) goto bail;
fout = open(out, O_WRONLY|O_CREAT|O_TRUNC, st.st_mode & 0777);
if (fout == -1) goto bail;
bi = mmap(0, st.st_size, PROT_READ, MAP_PRIVATE, fin, 0);
ret = (bi == (void*)-1)
? 0 : (write(fout, bi, st.st_size) == st.st_size);
bail: if (fin != -1) close(fin);
if (fout != -1) close(fout);
if (bi != (void*)-1) munmap(bi, st.st_size);
return ret;
}

View file

@ -0,0 +1,40 @@
identification division.
program-id. copyfile.
environment division.
input-output section.
file-control.
select input-file assign to "input.txt"
organization sequential
.
select output-file assign to "output.txt"
organization sequential
.
data division.
file section.
fd input-file.
1 input-record pic x(80).
fd output-file.
1 output-record pic x(80).
working-storage section.
1 end-of-file-flag pic 9 value 0.
88 eof value 1.
1 text-line pic x(80).
procedure division.
begin.
open input input-file
output output-file
perform read-input
perform until eof
write output-record from text-line
perform read-input
end-perform
close input-file output-file
stop run
.
read-input.
read input-file into text-line
at end
set eof to true
end-read
.
end program copyfile.

View file

@ -0,0 +1,48 @@
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
.

View file

@ -0,0 +1,2 @@
*> Originally from ACUCOBOL-GT
CALL "C$COPY" USING "input.txt", "output.txt", 0

View file

@ -0,0 +1,2 @@
*> Originally from Micro Focus COBOL
CALL "CBL_COPY_FILE" USING "input.txt", "output.txt"

View file

@ -0,0 +1,19 @@
import StdEnv
copyFile fromPath toPath world
# (ok, fromFile, world) = fopen fromPath FReadData world
| not ok = abort ("Cannot open " +++ fromPath +++ " for reading")
# (ok, toFile, world) = fopen toPath FWriteData world
| not ok = abort ("Cannot open " +++ toPath +++ " for writing")
# (fromFile, toFile) = copyData 1024 fromFile toFile
# (ok, world) = fclose fromFile world
| not ok = abort ("Cannot close " +++ fromPath +++ " after reading")
# (ok, world) = fclose toFile world
| not ok = abort ("Cannot close " +++ toPath +++ " after writing")
= world
where
copyData bufferSize fromFile toFile
# (buffer, fromFile) = freads fromFile bufferSize
# toFile = fwrites buffer toFile
| size buffer < bufferSize = (fromFile, toFile) // we're done
= copyData bufferSize fromFile toFile // continue recursively

View file

@ -0,0 +1 @@
Start world = copyFile "input.txt" "output.txt" world

View file

@ -0,0 +1,3 @@
(use 'clojure.java.io)
(copy (file "input.txt") (file "output.txt"))

View file

@ -0,0 +1,5 @@
;; simple file writing
(spit "filename.txt" "your content here")
;; simple file reading
(slurp "filename.txt")

View file

@ -0,0 +1,4 @@
<cfif fileExists(expandPath("input.txt"))>
<cffile action="read" file="#expandPath('input.txt')#" variable="inputContents">
<cffile action="write" file="#expandPath('output.txt')#" output="#inputContents#">
</cfif>

View file

@ -0,0 +1,13 @@
10 print chr$(14) : rem switch to upper+lower case set
20 print "read seq file input.txt and write to seq file output.txt"
30 open 4,8,4,"input.txt,seq,read"
40 open 8,8,8,"@:output.txt,seq,write" : rem '@'== new file
50 for i=0 to 1 : rem while i==0
60 input#4,a$
70 i=64 and st : rem check bit 6=='end of file'
80 print a$
90 print#8,a$
100 next : rem end while
110 close 4
120 close 8
130 end

View file

@ -0,0 +1,5 @@
(with-open-file (in #p"input.txt" :direction :input)
(with-open-file (out #p"output.txt" :direction :output)
(loop for line = (read-line in nil 'foo)
until (eq line 'foo)
do (write-line line out))))

View file

@ -0,0 +1,12 @@
(defconstant +buffer-size+ (expt 2 16))
(with-open-file (in #p"input.txt" :direction :input
:element-type '(unsigned-byte 8))
(with-open-file (out #p"output.txt"
:direction :output
:element-type (stream-element-type in))
(loop with buffer = (make-array +buffer-size+
:element-type (stream-element-type in))
for size = (read-sequence buffer in)
while (plusp size)
do (write-sequence buffer out :end size))))

View file

@ -0,0 +1,5 @@
import std.file: copy;
void main() {
copy("input.txt", "output.txt");
}

View file

@ -0,0 +1,5 @@
void main() {
import std.file;
auto data = std.file.read("input.txt");
std.file.write("output.txt", data);
}

View file

@ -0,0 +1,15 @@
import std.stdio;
int main() {
auto from = File("input.txt", "rb");
scope(exit) from.close();
auto to = File("output.txt", "wb");
scope(exit) to.close();
foreach(buffer; from.byChunk(new ubyte[4096*1024])) {
to.rawWrite(buffer);
}
return 0;
}

View file

@ -0,0 +1,9 @@
import tango.io.device.File;
void main()
{
auto from = new File("input.txt");
auto to = new File("output.txt", File.WriteCreate);
to.copy(from).close;
from.close;
}

View file

@ -0,0 +1,7 @@
import tango.io.device.File;
void main()
{
auto to = new File("output.txt", File.WriteCreate);
to.copy(new File("input.txt")).close;
}

View file

@ -0,0 +1,100 @@
;
; File Input and output examples for DBL version 4 by Dario B.
;
RECORD CUSTOM
CUCOD, D5 ;customer code
CUNAM, A20 ;name
CUCIT, A20 ;city
, A55
;------- 100 bytes -------------
A80, A80
PROC
;--------------------------------------------------------------
XCALL FLAGS (0007000000,1) ;suppress STOP message
CLOSE 1
OPEN (1,O,'TT:') ;open video
CLOSE 2
OPEN (2,O,"CUSTOM.DDF") ;create file in output
;Add new record
CLEAR CUSTOM
CUCOD=1
CUNAM="Alan Turing"
CUCIT="London"
WRITES (2,CUSTOM)
;Add new record
CLEAR CUSTOM
CUCOD=2
CUNAM="Galileo Galilei"
CUCIT="Pisa"
WRITES (2,CUSTOM)
;Modify a record
CLOSE 2
OPEN (2,U,"CUSTOM.DDF") [ERR=NOCUS] ;open in update
READ (2,CUSTOM,2) [ERR=NOREC]
CUCIT="Pisa - Italy"
WRITE (2,CUSTOM,2) [ERR=NOWRI]
;Add new record
CLOSE 2
OPEN (2,A,"CUSTOM.DDF") [ERR=NOCUS] ;open in append
CLEAR CUSTOM
CUCOD=3
CUNAM="Kenneth Lane Thompson"
CUCIT="New Orleans"
WRITES (2,CUSTOM)
CLOSE 2
;Read file and display a video
CLOSE 2
OPEN (2,I,"CUSTOM.DDF") [ERR=NOCUS]
DO FOREVER
BEGIN
READS (2,CUSTOM,EOF) [ERR=NOREC]
DISPLAY (1,13,CUSTOM)
END
EOF, DISPLAY (1,10)
CLOSE 2
;Write/read a text file
CLOSE 3
OPEN (3,O,"FILE.TXT")
DISPLAY (3,"An Occurrence at Owl Creek Bridge",13,10)
DISPLAY (3,"A man stood upon a railroad bridge in northern Alabama,",13,10)
DISPLAY (3,"looking down into the swift water twenty feet below.",13,10)
DISPLAY (3,"The man's hands were behind his back, the wrists bound ")
DISPLAY (3,"with a cord.",13,10)
CLOSE 3
OPEN (3,I,"FILE.TXT")
DO FOREVER
BEGIN
READS (3,A80,EOFF)
DISPLAY (1,A80(1:%TRIM(A80)),10)
END
EOFF, CLOSE 3
DISPLAY (1,10)
GOTO QUIT
;---------------------------------------------------------------
NOCUS, DISPLAY (1,10,"File CUSTUM.DDF Not found!",10)
GOTO QUIT
NOREC, DISPLAY (1,10,"Read error!",10)
GOTO QUIT
NOWRI, DISPLAY (1,10,"Write error!",10)
GOTO QUIT
QUIT, CLOSE 1
STOP

View file

@ -0,0 +1,9 @@
$ open input input.txt
$ open /write output output.txt
$ loop:
$ read /end_of_file = done input line
$ write output line
$ goto loop
$ done:
$ close input
$ close output

View file

@ -0,0 +1,21 @@
START ;Simple File Input and Output
RECORD TEMP
INLINE, A72
PROC
OPEN (8,I,"input.txt")
OPEN (9,O,"output.txt")
LOOP,
READS(8,TEMP,END)
WRITES(9,TEMP)
GOTO LOOP
END,
CLOSE 8
CLOSE 9
END

View file

@ -0,0 +1,11 @@
var
f : TextFile ;
s : string ;
begin
AssignFile(f,[fully qualified file name);
Reset(f);
writeln(f,s);
Reset(f);
ReadLn(F,S);
CloseFile(
end;

View file

@ -0,0 +1,10 @@
var
f : File ;
buff : array[1.1024] of byte ;
BytesRead : Integer ;
begin
AssignFile(f,fully qualified file name);
Reset(f,1);
Blockread(f,Buff,SizeOf(Buff),BytesRead);
CloseFile(f);
end;

View file

@ -0,0 +1,27 @@
type
tAddressBook = Record
FName : string[20];
LName : string[30];
Address : string[30];
City : string[30];
State : string[2];
Zip5 : string[5];
Zip4 : string[4];
Phone : string[14];
Deleted : boolean ;
end;
var
f : file of tAddressBook ;
v : tAddressBook ;
bytes : integer ;
begin
AssignFile(f,fully qualified file name);
Reset(f);
Blockread(f,V,1,Bytes);
Edit(v);
Seek(F,FilePos(f)-1);
BlockWrite(f,v,1,bytes);
CloseFile(f);
end;

View file

@ -0,0 +1 @@
<file:output.txt>.setText(<file:input.txt>.getText())

View file

@ -0,0 +1,33 @@
class
APPLICATION
create
make
feature {NONE} -- Initialization
make
-- Run application.
do
create input_file.make_open_read ("input.txt")
create output_file.make_open_write ("output.txt")
from
input_file.read_character
until
input_file.exhausted
loop
output_file.put (input_file.last_character)
input_file.read_character
end
input_file.close
output_file.close
end
feature -- Access
input_file: PLAIN_TEXT_FILE
output_file: PLAIN_TEXT_FILE
end

View file

@ -0,0 +1,8 @@
import system'io;
public program()
{
var text := File.assign("input.txt").readContent();
File.assign("output.txt").saveContent(text);
}

View file

@ -0,0 +1,16 @@
defmodule FileReadWrite do
def copy(path,new_path) do
case File.read(path) do
# In case of success, write to the new file
{:ok, body} ->
# Can replace with :write! to generate an error upon failure
File.write(new_path,body)
# If not successful, raise an error
{:error,reason} ->
# Using Erlang's format_error to generate error string
:file.format_error(reason)
end
end
end
FileReadWrite.copy("input.txt","output.txt")

View file

@ -0,0 +1 @@
File.cp!("input.txt", "output.txt")

View file

@ -0,0 +1,6 @@
(defvar input (with-temp-buffer
(insert-file-contents "input.txt")
(buffer-string)))
(with-temp-file "output.txt"
(insert input))

View file

@ -0,0 +1,7 @@
-module( file_io ).
-export( [task/0] ).
task() ->
{ok, Contents} = file:read_file( "input.txt" ),
ok = file:write_file( "output.txt", Contents ).

View file

@ -0,0 +1,2 @@
include std/io.e
write_lines("output.txt", read_lines("input.txt"))

View file

@ -0,0 +1,16 @@
integer in,out
object line
in = open("input.txt","r")
out = open("output.txt","w")
while 1 do
line = gets(in)
if atom(line) then -- EOF reached
exit
end if
puts(out,line)
end while
close(out)
close(in)

View file

@ -0,0 +1,10 @@
open System.IO
let copyFile fromTextFileName toTextFileName =
let inputContent = File.ReadAllText fromTextFileName
inputContent |> fun text -> File.WriteAllText(toTextFileName, text)
[<EntryPoint>]
let main argv =
copyFile "input.txt" "output.txt"
0

View file

@ -0,0 +1,2 @@
"input.txt" binary file-contents
"output.txt" binary set-file-contents

View file

@ -0,0 +1,4 @@
[
"input.txt" binary <file-reader> &dispose
"output.txt" binary <file-writer> stream-copy
] with-destructors

View file

@ -0,0 +1 @@
"input.txt" "output.txt" copy-file

View file

@ -0,0 +1,14 @@
\ <to> <from> copy-file
: copy-file ( a1 n1 a2 n2 -- )
r/o open-file throw >r
w/o create-file throw r>
begin
pad maxstring 2 pick read-file throw
?dup while
pad swap 3 pick write-file throw
repeat
close-file throw
close-file throw ;
\ Invoke it like this:
s" output.txt" s" input.txt" copy-file

View file

@ -0,0 +1,10 @@
: INPUT$ ( text -- n n )
pad swap accept pad swap ;
cr ." Enter file name : " 20 INPUT$ w/o create-file throw Value fd-out
: get-content cr ." Enter your nickname : " 20 INPUT$ fd-out write-file cr ;
: close-output ( -- ) fd-out close-file throw ;
get-content
\ Inject a carriage return at end of file
s\" \n" fd-out write-file
close-output
bye

View file

@ -0,0 +1,21 @@
program FileIO
integer, parameter :: out = 123, in = 124
integer :: err
character :: c
open(out, file="output.txt", status="new", action="write", access="stream", iostat=err)
if (err == 0) then
open(in, file="input.txt", status="old", action="read", access="stream", iostat=err)
if (err == 0) then
err = 0
do while (err == 0)
read(unit=in, iostat=err) c
if (err == 0) write(out) c
end do
close(in)
end if
close(out)
end if
end program FileIO

View file

@ -0,0 +1,22 @@
' FB 1.05.0 Win64
/'
input.txt contains:
The quick brown fox jumps over the lazy dog.
Empty vessels make most noise.
Too many chefs spoil the broth.
A rolling stone gathers no moss.
'/
Open "output.txt" For Output As #1
Open "input.txt" For Input As #2
Dim line_ As String ' note that line is a keyword
While Not Eof(2)
Line Input #2, line_
Print #1, line_
Wend
Close #2
Close #1

View file

@ -0,0 +1,4 @@
contents = read["file:input.txt"]
w = new Writer["output.txt"]
w.print[contents]
w.close[]

View file

@ -0,0 +1,39 @@
/*
Rosetta Code File input/output example
FutureBasic 7.0.14
Rich Love
9/25/22
Before running this, use TextEdit to create a file called input.txt on your desktop.
Format as plain text and create a few lines of text.
Then save.
*/
output file "FileInputOutput.app"
CFURLRef ParentDirectory // Create a url for the desktop
ParentDirectory = fn FileManagerURLForDirectory( NSDesktopDirectory, NSUserDomainMask )
CFURLRef inputURL // Create a url for input.txt on the desktop
inputURL = fn URLByAppendingPathComponent( ParentDirectory, @"input.txt" )
CFURLRef outputURL // Create a url for output.txt on the desktop
outputURL = fn URLByAppendingPathComponent( ParentDirectory, @"output.txt" )
open "O", 1, outputURL
open "I", 2, inputURL
str255 dataLine
While Not Eof(2)
Line Input #2, dataLine
Print #1, dataLine
Wend
Close #1
Close #2
end

View file

@ -0,0 +1,15 @@
CopyFile := function(src, dst)
local f, g, line;
f := InputTextFile(src);
g := OutputTextFile(dst, false);
while true do
line := ReadLine(f);
if line = fail then
break
else
WriteLine(g, Chomp(line));
fi;
od;
CloseStream(f);
CloseStream(g);
end;

View file

@ -0,0 +1,18 @@
var file, str;
file = file_text_open_read("input.txt");
str = "";
while (!file_text_eof(file))
{
str += file_text_read_string(file);
if (!file_text_eof(file))
{
str += "
"; //It is important to note that a linebreak is actually inserted here rather than a character code of some kind
file_text_readln(file);
}
}
file_text_close(file);
file = file_text_open_write("output.txt");
file_text_write_string(file,str);
file_text_close(file);

View file

@ -0,0 +1,2 @@
Start,My Documents,Rightclick:input.txt,Copy,Menu,Edit,Paste,
Rightclick:Copy of input.txt,Rename,Type:output.txt[enter]

View file

@ -0,0 +1,11 @@
Public Sub Main()
Dim sOutput As String = "Hello "
Dim sInput As String = File.Load(User.Home &/ "input.txt") 'Has the word 'World!' stored
File.Save(User.Home &/ "output.txt", sOutput)
File.Save(User.Home &/ "input.txt", sOutput & sInput)
Print "'input.txt' contains - " & sOutput & sInput
Print "'output.txt' contains - " & sOutput
End

View file

@ -0,0 +1,17 @@
package main
import (
"fmt"
"io/ioutil"
)
func main() {
b, err := ioutil.ReadFile("input.txt")
if err != nil {
fmt.Println(err)
return
}
if err = ioutil.WriteFile("output.txt", b, 0666); err != nil {
fmt.Println(err)
}
}

View file

@ -0,0 +1,37 @@
package main
import (
"io"
"log"
"os"
)
func CopyFile(out, in string) (err error) {
var inf, outf *os.File
inf, err = os.Open(in)
if err != nil {
return
}
defer func() {
cErr := inf.Close()
if err == nil {
err = cErr
}
}()
outf, err = os.Create(out)
if err != nil {
return
}
_, err = io.Copy(outf, inf)
cErr := outf.Close()
if err == nil {
err = cErr
}
return
}
func main() {
if err := CopyFile("output.txt", "input.txt"); err != nil {
log.Fatal(err)
}
}

View file

@ -0,0 +1,2 @@
content = new File('input.txt').text
new File('output.txt').write(content)

View file

@ -0,0 +1 @@
new AntBuilder().copy(file:'input.txt', toFile:'output.txt', overwrite:true)

View file

@ -0,0 +1,3 @@
new File('output.txt').withWriter( w ->
new File('input.txt').withReader( r -> w << r }
}

View file

@ -0,0 +1 @@
main = readFile "input.txt" >>= writeFile "output.txt"

View file

@ -0,0 +1,6 @@
let in openin "input.txt"
let out openout "output.txt"
while !(catch (let c read char in))
write c out
endwhile
close in; close out

View file

@ -0,0 +1,2 @@
CHARACTER input='input.txt ', output='output.txt ', c, buffer*4096
SYSTEM(COPY=input//output, ERror=11) ! on error branch to label 11 (not shown)

View file

@ -0,0 +1,7 @@
OPEN(FIle=input, OLD, ERror=21) ! on error branch to label 21 (not shown)
OPEN(FIle=output)
DO i = 1, 1E300 ! "infinite" loop, exited on end-of-file error
READ( FIle=input, ERror=22) buffer ! on error (end of file) branch to label 22
WRITE(FIle=output, ERror=23) buffer ! on error branch to label 23 (not shown)
ENDDO
22 WRITE(FIle=output, CLoSe=1)

View file

@ -0,0 +1,5 @@
OPEN(FIle=input, SEQuential, UNFormatted, OLD, LENgth=len, ERror=31) ! on error branch to label 31 (not shown)
OPEN(FIle=output, SEQuential, UNFormatted, ERror=32) ! on error branch to label 32 (not shown)
ALLOCATE(c, len)
READ(FIle=input, CLoSe=1) c
WRITE(FIle=output, CLoSe=1) c END

View file

@ -0,0 +1,4 @@
software {
file = load("input.txt")
open("output.txt").write(file)
}

View file

@ -0,0 +1,12 @@
; open two LUNs
openw,unit1,'output.txt,/get
openr,unit2,'input.txt',/get
; how many bytes to read
fs = fstat(unit2)
; make buffer
buff = bytarr(fs.size)
; transfer content
readu,unit2,buff
writeu,unit1,buff
; that's all
close,/all

Some files were not shown because too many files have changed in this diff Show more