Update all new Tasks

This commit is contained in:
Ingy döt Net 2015-02-20 09:02:09 -05:00
parent 00a190b0a6
commit 91df62d461
5697 changed files with 93386 additions and 804 deletions

View file

@ -0,0 +1,3 @@
{{selection|Short Circuit|Console Program Basics}}
In this task, the job is to 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: (1) how to read from a file into a variable, and (2) how to write a variable's contents into a file. Oneliners that skip the intermediate variable are of secondary interest — operating systems have copy commands for that.

View file

@ -0,0 +1,2 @@
---
note: File handling

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,5 @@
BEGIN {
while ( (getline <"input.txt") > 0 ) {
print >"output.txt"
}
}

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;
f_open(i, "input.txt", OPEN_READONLY, 0);
f_open(o, "output.txt", OPEN_CREATE | OPEN_TRUNCATE | OPEN_WRITEONLY,
0644);
while (f_line(i, s) ^ -1) {
f_text(o, s);
f_byte(o, '\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,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,9 @@
OPEN "INPUT.TXT" FOR INPUT AS #1
OPEN "OUTPUT.TXT" FOR OUTPUT AS #2
DO UNTIL EOF(1)
LINE INPUT #1, Data$
PRINT #2, Data$
LOOP
CLOSE #1
CLOSE #2
SYSTEM

View file

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

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,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 @@
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,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,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,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,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,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,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,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,21 @@
program FileIO
integer, parameter :: out = 123, in = 124
integer :: err
character(len=1) :: 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,4 @@
contents = read["file:input.txt"]
w = new Writer["output.txt"]
w.print[contents]
w.close[]

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,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 @@
new File('output.txt').write(new File('input.txt').text)

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,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,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

View file

@ -0,0 +1,5 @@
procedure main()
in := open(f := "input.txt","r") | stop("Unable to open ",f)
out := open(f := "output.txt","w") | stop("Unable to open ",f)
while write(out,read(in))
end

View file

@ -0,0 +1,9 @@
inf := File with("input.txt") openForReading
outf := File with("output.txt") openForUpdating
while(l := inf readLine,
outf write(l, "\n")
)
inf close
outf close

View file

@ -0,0 +1 @@
'output.txt' (1!:2~ 1!:1)&< 'input.txt'

View file

@ -0,0 +1,2 @@
require 'files'
'output.txt' (fwrite~ fread) 'input.txt'

View file

@ -0,0 +1,18 @@
import java.io.*;
public class FileIODemo {
public static void main(String[] args) {
try {
FileInputStream in = new FileInputStream("input.txt");
FileOutputStream out = new FileOutputStream("ouput.txt");
int c;
while ((c = in.read()) != -1) {
out.write(c);
}
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e){
e.printStackTrace();
}
}
}

View file

@ -0,0 +1,30 @@
import java.io.*;
public class FileIODemo2 {
public static void main(String args[]) {
try {
// Probably should wrap with a BufferedInputStream
final InputStream in = new FileInputStream("input.txt");
try {
// Probably should wrap with a BufferedOutputStream
final OutputStream out = new FileOutputStream("output.txt");
try {
int c;
while ((c = in.read()) != -1) {
out.write(c);
}
}
finally {
out.close();
}
}
finally {
in.close();
}
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e){
e.printStackTrace();
}
}
}

View file

@ -0,0 +1,26 @@
import java.io.*;
import java.nio.channels.*;
public class FileIODemo3 {
public static void main(String args[]) {
try {
final FileChannel in = new FileInputStream("input.txt").getChannel();
try {
final FileChannel out = new FileOutputStream("output.txt").getChannel();
try {
out.transferFrom(in, 0, in.size());
}
finally {
out.close();
}
}
finally {
in.close();
}
}
catch (Exception e) {
System.err.println("Exception while trying to copy: "+e);
e.printStackTrace(); // stack trace of place where it happened
}
}
}

View file

@ -0,0 +1,14 @@
import java.io.*;
public class Test {
public static void main (String[] args) throws IOException {
BufferedReader br = new BufferedReader(new FileReader("input.txt"));
BufferedWriter bw = new BufferedWriter(new FileWriter("output.txt"));
String line;
while ((line = br.readLine()) != null) {
bw.write(line);
bw.newLine();
}
br.close();
bw.close();
}
}

View file

@ -0,0 +1,9 @@
import java.nio.file.*;
public class Copy{
public static void main(String[] args) throws Exception{
FileSystem fs = FileSystems.getDefault();
Path in = fs.getPath("input.txt");
Path out = fs.getPath("output.txt");
Files.copy(in, out, StandardCopyOption.REPLACE_EXISTING);
}
}

View file

@ -0,0 +1,15 @@
var fso = new ActiveXObject("Scripting.FileSystemObject");
var ForReading = 1, ForWriting = 2;
var f_in = fso.OpenTextFile('input.txt', ForReading);
var f_out = fso.OpenTextFile('output.txt', ForWriting, true);
// for small files:
// f_out.Write( f_in.ReadAll() );
while ( ! f_in.AtEndOfStream) {
// ReadLine() does not include the newline char
f_out.WriteLine( f_in.ReadLine() );
}
f_in.Close();
f_out.Close();

View file

@ -0,0 +1,2 @@
var fs = require('fs');
require('util').pump(fs.createReadStream('input.txt', {flags:'r'}), fs.createWriteStream('output.txt', {flags:'w+'}));

View file

@ -0,0 +1,2 @@
string = open(readall, "file1", "r")
open(io->write(io, string), "file2", "w")

View file

@ -0,0 +1 @@
cp("file1","file2")

View file

@ -0,0 +1,5 @@
infile = open("file1", "r")
outfile = open("file2", "w")
write(outfile, readall(infile))
close(outfile)
close(infile)

View file

@ -0,0 +1 @@
open(IO ->write(IO, open(readall, "file1", "r")), "file2", "w")

View file

@ -0,0 +1 @@
`output.txt 0:0:`input.txt

View file

@ -0,0 +1,7 @@
: puts(*) . "\n" . ;
: set-file '> swap open ;
: >>contents slurp puts ;
: copy-file
swap set-file 'fdst set fdst fout >>contents fdst close ;
'output.txt 'input.txt copy-file

View file

@ -0,0 +1,12 @@
nomainwin
open "input.txt" for input as #f1
qtyBytes = lof( #f1)
source$ = input$( #f1, qtyBytes)
close #f1
open "output.txt" for output as #f2
#f2 source$;
close #f2
end

View file

@ -0,0 +1,32 @@
Section Header
+ name := FILE_IO;
Section Public
- main <- (
+ e : ENTRY;
+ f : STD_FILE;
+ s : STRING;
e := FILE_SYSTEM.get "input.txt";
(e != NULL).if {
f ?= e.open_read_only;
(f != NULL).if {
s := STRING.create(f.size);
f.read s size (f.size);
f.close;
};
};
(s != NULL).if {
e := FILE_SYSTEM.make_file "output.txt";
(e != NULL).if {
f ?= e.open;
(f != NULL).if {
f.write s from (s.lower) size (s.count);
f.close;
};
};
};
);

View file

@ -0,0 +1,10 @@
to copy :from :to
openread :from
openwrite :to
setread :from
setwrite :to
until [eof?] [print readrawline]
closeall
end
copy "input.txt "output.txt

View file

@ -0,0 +1,12 @@
inFile = io.open("input.txt", "r")
data = inFile:read("*all") -- may be abbreviated to "*a";
-- other options are "*line",
-- or the number of characters to read.
inFile:close()
outFile = io.open("output.txt", "w")
outfile:write(data)
outfile:close()
-- Oneliner version:
io.open("output.txt", "w"):write(io.open("input.txt", "r"):read("*a"))

View file

@ -0,0 +1,8 @@
inFile = openFile "input.txt"
outFile = createFile "output.txt"
while not EOF inFile do
(
format "%" (readLine inFile) to:outFile
)
close inFile
close outFile

View file

@ -0,0 +1,3 @@
SetDirectory@NotebookDirectory[];
If[FileExistsQ["output.txt"], DeleteFile["output.txt"], Print["No output yet"] ];
CopyFile["input.txt", "output.txt"]

View file

@ -0,0 +1,40 @@
:- module file_io.
:- interface.
:- import_module io.
:- pred main(io::di, io::uo) is det.
:- implementation.
main(!IO) :-
io.open_input("input.txt", InputRes, !IO),
(
InputRes = ok(Input),
io.read_file_as_string(Input, ReadRes, !IO),
(
ReadRes = ok(Contents),
io.close_input(Input, !IO),
io.open_output("output.txt", OutputRes, !IO),
(
OutputRes = ok(Output),
io.write_string(Output, Contents, !IO),
io.close_output(Output, !IO)
;
OutputRes = error(OutputError),
print_io_error(OutputError, !IO)
)
;
ReadRes = error(_, ReadError),
print_io_error(ReadError, !IO)
)
;
InputRes = error(InputError),
print_io_error(InputError, !IO)
).
:- pred print_io_error(io.error::in, io::di, io::uo) is det.
print_io_error(Error, !IO) :-
io.stderr_stream(Stderr, !IO),
io.write_string(Stderr, io.error_message(Error), !IO),
io.set_exit_status(1, !IO).

View file

@ -0,0 +1,19 @@
MODULE FileIO EXPORTS Main;
IMPORT IO, Rd, Wr;
<*FATAL ANY*>
VAR
infile: Rd.T;
outfile: Wr.T;
txt: TEXT;
BEGIN
infile := IO.OpenRead("input.txt");
outfile := IO.OpenWrite("output.txt");
txt := Rd.GetText(infile, LAST(CARDINAL));
Wr.PutText(outfile, txt);
Rd.Close(infile);
Wr.Close(outfile);
END FileIO.

View file

@ -0,0 +1,27 @@
/* NetRexx */
options replace format comments java crossref symbols nobinary
import java.nio.
parse arg infileName outfileName .
if infileName = '' | infileName.length = 0 then infileName = 'data/input.txt'
if outfileName = '' | outfileName.length = 0 then outfileName = 'data/output.txt'
binaryCopy(infileName, outfileName)
return
method binaryCopy(infileName, outfileName) public static
do
infile = Paths.get('.', [String infileName])
outfile = Paths.get('.', [String outfileName])
fileOctets = Files.readAllBytes(infile)
Files.write(outfile, fileOctets, [StandardOpenOption.WRITE, StandardOpenOption.CREATE])
catch ioex = IOException
ioex.printStackTrace()
end
return

View file

@ -0,0 +1,13 @@
let () =
let ic = open_in "input.txt" in
let oc = open_out "output.txt" in
try
while true do
let s = input_line ic in
output_string oc s;
output_char oc '\n';
done
with End_of_file ->
close_in ic;
close_out oc;
;;

View file

@ -0,0 +1,12 @@
let () =
let ic = open_in "input.txt" in
let oc = open_out "output.txt" in
try
while true do
let c = input_char ic in
output_char oc c
done
with End_of_file ->
close_in ic;
close_out oc;
;;

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