A-M baby
This commit is contained in:
parent
764da6cbbb
commit
db842d013d
19005 changed files with 197040 additions and 7 deletions
3
Task/File-IO/0DESCRIPTION
Normal file
3
Task/File-IO/0DESCRIPTION
Normal 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.
|
||||
2
Task/File-IO/1META.yaml
Normal file
2
Task/File-IO/1META.yaml
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
---
|
||||
note: File handling
|
||||
39
Task/File-IO/ACL2/file-io.acl2
Normal file
39
Task/File-IO/ACL2/file-io.acl2
Normal 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)))
|
||||
46
Task/File-IO/ALGOL-68/file-io.alg
Normal file
46
Task/File-IO/ALGOL-68/file-io.alg
Normal 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")
|
||||
)
|
||||
5
Task/File-IO/AWK/file-io.awk
Normal file
5
Task/File-IO/AWK/file-io.awk
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
BEGIN {
|
||||
while ( (getline <"input.txt") > 0 ) {
|
||||
print >"output.txt"
|
||||
}
|
||||
}
|
||||
24
Task/File-IO/Ada/file-io-1.ada
Normal file
24
Task/File-IO/Ada/file-io-1.ada
Normal file
|
|
@ -0,0 +1,24 @@
|
|||
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;
|
||||
exception
|
||||
when End_Error =>
|
||||
Close (Input);
|
||||
Close (Output);
|
||||
end Read_And_Write_File_Line_By_Line;
|
||||
45
Task/File-IO/Ada/file-io-2.ada
Normal file
45
Task/File-IO/Ada/file-io-2.ada
Normal file
|
|
@ -0,0 +1,45 @@
|
|||
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;
|
||||
exception
|
||||
when End_Error =>
|
||||
Close (Input);
|
||||
Close (Output);
|
||||
end Read_And_Write_File_Line_By_Line;
|
||||
20
Task/File-IO/Ada/file-io-3.ada
Normal file
20
Task/File-IO/Ada/file-io-3.ada
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
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;
|
||||
exception
|
||||
when End_Error =>
|
||||
Close (Input);
|
||||
Close (Output);
|
||||
end Read_And_Write_File_Character_By_Character;
|
||||
18
Task/File-IO/Ada/file-io-4.ada
Normal file
18
Task/File-IO/Ada/file-io-4.ada
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
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;
|
||||
exception
|
||||
when End_Error =>
|
||||
Close (Input);
|
||||
Close (Output);
|
||||
end Using_Text_Streams;
|
||||
8
Task/File-IO/AppleScript/file-io.applescript
Normal file
8
Task/File-IO/AppleScript/file-io.applescript
Normal 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"
|
||||
2
Task/File-IO/AutoHotkey/file-io-1.ahk
Normal file
2
Task/File-IO/AutoHotkey/file-io-1.ahk
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
Loop, Read, input.txt, output.txt
|
||||
FileAppend, %A_LoopReadLine%`n
|
||||
2
Task/File-IO/AutoHotkey/file-io-2.ahk
Normal file
2
Task/File-IO/AutoHotkey/file-io-2.ahk
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
FileRead, var, input.txt
|
||||
FileAppend, %var%, output.txt
|
||||
1
Task/File-IO/AutoHotkey/file-io-3.ahk
Normal file
1
Task/File-IO/AutoHotkey/file-io-3.ahk
Normal file
|
|
@ -0,0 +1 @@
|
|||
FileCopy, input.txt, output.txt
|
||||
9
Task/File-IO/BASIC/file-io.bas
Normal file
9
Task/File-IO/BASIC/file-io.bas
Normal 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
|
||||
1
Task/File-IO/BBC-BASIC/file-io-1.bbc
Normal file
1
Task/File-IO/BBC-BASIC/file-io-1.bbc
Normal file
|
|
@ -0,0 +1 @@
|
|||
*COPY input.txt output.txt
|
||||
7
Task/File-IO/BBC-BASIC/file-io-2.bbc
Normal file
7
Task/File-IO/BBC-BASIC/file-io-2.bbc
Normal 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%
|
||||
4
Task/File-IO/Babel/file-io.pb
Normal file
4
Task/File-IO/Babel/file-io.pb
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
main:
|
||||
{ "input.txt" >>> -- File is now on stack
|
||||
foo set -- File is now in 'foo'
|
||||
foo "output.txt" <<< }
|
||||
1
Task/File-IO/Batch-File/file-io-1.bat
Normal file
1
Task/File-IO/Batch-File/file-io-1.bat
Normal file
|
|
@ -0,0 +1 @@
|
|||
copy input.txt output.txt
|
||||
1
Task/File-IO/Batch-File/file-io-2.bat
Normal file
1
Task/File-IO/Batch-File/file-io-2.bat
Normal file
|
|
@ -0,0 +1 @@
|
|||
type input.txt > output.txt
|
||||
1
Task/File-IO/Batch-File/file-io-3.bat
Normal file
1
Task/File-IO/Batch-File/file-io-3.bat
Normal file
|
|
@ -0,0 +1 @@
|
|||
for /f "" %L in ('more^<input.txt') do echo %L>>output.txt
|
||||
1
Task/File-IO/Befunge/file-io.bf
Normal file
1
Task/File-IO/Befunge/file-io.bf
Normal file
|
|
@ -0,0 +1 @@
|
|||
0110"txt.tupni"#@i10"txt.tuptuo"#@o@
|
||||
1
Task/File-IO/Bracmat/file-io.bracmat
Normal file
1
Task/File-IO/Bracmat/file-io.bracmat
Normal file
|
|
@ -0,0 +1 @@
|
|||
put$(get$"input.txt","output.txt",NEW)
|
||||
28
Task/File-IO/C++/file-io-1.cpp
Normal file
28
Task/File-IO/C++/file-io-1.cpp
Normal 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;
|
||||
}
|
||||
29
Task/File-IO/C++/file-io-2.cpp
Normal file
29
Task/File-IO/C++/file-io-2.cpp
Normal 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;
|
||||
}
|
||||
10
Task/File-IO/C++/file-io-3.cpp
Normal file
10
Task/File-IO/C++/file-io-3.cpp
Normal 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));
|
||||
}
|
||||
8
Task/File-IO/C++/file-io-4.cpp
Normal file
8
Task/File-IO/C++/file-io-4.cpp
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
#include <fstream>
|
||||
|
||||
int main()
|
||||
{
|
||||
std::ifstream input("input.txt");
|
||||
std::ofstream output("output.txt");
|
||||
output << input.rdbuf();
|
||||
}
|
||||
27
Task/File-IO/C/file-io-1.c
Normal file
27
Task/File-IO/C/file-io-1.c
Normal 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;
|
||||
}
|
||||
36
Task/File-IO/C/file-io-2.c
Normal file
36
Task/File-IO/C/file-io-2.c
Normal 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;
|
||||
}
|
||||
23
Task/File-IO/C/file-io-3.c
Normal file
23
Task/File-IO/C/file-io-3.c
Normal 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;
|
||||
}
|
||||
19
Task/File-IO/Clean/file-io-1.clean
Normal file
19
Task/File-IO/Clean/file-io-1.clean
Normal 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
|
||||
1
Task/File-IO/Clean/file-io-2.clean
Normal file
1
Task/File-IO/Clean/file-io-2.clean
Normal file
|
|
@ -0,0 +1 @@
|
|||
Start world = copyFile "input.txt" "output.txt" world
|
||||
3
Task/File-IO/Clojure/file-io-1.clj
Normal file
3
Task/File-IO/Clojure/file-io-1.clj
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
(use 'clojure.java.io)
|
||||
|
||||
(copy (file "input.txt") (file "output.txt"))
|
||||
5
Task/File-IO/Clojure/file-io-2.clj
Normal file
5
Task/File-IO/Clojure/file-io-2.clj
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
;; simple file writing
|
||||
(spit "filename.txt" "your content here")
|
||||
|
||||
;; simple file reading
|
||||
(slurp "filename.txt")
|
||||
4
Task/File-IO/ColdFusion/file-io.cfm
Normal file
4
Task/File-IO/ColdFusion/file-io.cfm
Normal 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>
|
||||
5
Task/File-IO/Common-Lisp/file-io-1.lisp
Normal file
5
Task/File-IO/Common-Lisp/file-io-1.lisp
Normal 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))))
|
||||
12
Task/File-IO/Common-Lisp/file-io-2.lisp
Normal file
12
Task/File-IO/Common-Lisp/file-io-2.lisp
Normal 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))))
|
||||
5
Task/File-IO/D/file-io-1.d
Normal file
5
Task/File-IO/D/file-io-1.d
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
import std.file: copy;
|
||||
|
||||
void main() {
|
||||
copy("input.txt", "output.txt");
|
||||
}
|
||||
9
Task/File-IO/D/file-io-2.d
Normal file
9
Task/File-IO/D/file-io-2.d
Normal 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;
|
||||
}
|
||||
7
Task/File-IO/D/file-io-3.d
Normal file
7
Task/File-IO/D/file-io-3.d
Normal 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;
|
||||
}
|
||||
11
Task/File-IO/Delphi/file-io-1.delphi
Normal file
11
Task/File-IO/Delphi/file-io-1.delphi
Normal 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;
|
||||
10
Task/File-IO/Delphi/file-io-2.delphi
Normal file
10
Task/File-IO/Delphi/file-io-2.delphi
Normal 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;
|
||||
27
Task/File-IO/Delphi/file-io-3.delphi
Normal file
27
Task/File-IO/Delphi/file-io-3.delphi
Normal 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;
|
||||
1
Task/File-IO/E/file-io.e
Normal file
1
Task/File-IO/E/file-io.e
Normal file
|
|
@ -0,0 +1 @@
|
|||
<file:output.txt>.setText(<file:input.txt>.getText())
|
||||
33
Task/File-IO/Eiffel/file-io.e
Normal file
33
Task/File-IO/Eiffel/file-io.e
Normal 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
|
||||
1
Task/File-IO/Erlang/file-io.erl
Normal file
1
Task/File-IO/Erlang/file-io.erl
Normal file
|
|
@ -0,0 +1 @@
|
|||
file:copy("input.txt","output.txt").
|
||||
2
Task/File-IO/Euphoria/file-io-1.euphoria
Normal file
2
Task/File-IO/Euphoria/file-io-1.euphoria
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
include std/io.e
|
||||
write_lines("output.txt", read_lines("input.txt"))
|
||||
16
Task/File-IO/Euphoria/file-io-2.euphoria
Normal file
16
Task/File-IO/Euphoria/file-io-2.euphoria
Normal 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)
|
||||
2
Task/File-IO/Factor/file-io-1.factor
Normal file
2
Task/File-IO/Factor/file-io-1.factor
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
"input.txt" binary file-contents
|
||||
"output.txt" binary set-file-contents
|
||||
4
Task/File-IO/Factor/file-io-2.factor
Normal file
4
Task/File-IO/Factor/file-io-2.factor
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
[
|
||||
"input.txt" binary <file-reader> &dispose
|
||||
"output.txt" binary <file-writer> stream-copy
|
||||
] with-destructors
|
||||
1
Task/File-IO/Factor/file-io-3.factor
Normal file
1
Task/File-IO/Factor/file-io-3.factor
Normal file
|
|
@ -0,0 +1 @@
|
|||
"input.txt" "output.txt" copy-file
|
||||
14
Task/File-IO/Forth/file-io.fth
Normal file
14
Task/File-IO/Forth/file-io.fth
Normal 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
|
||||
21
Task/File-IO/Fortran/file-io.f
Normal file
21
Task/File-IO/Fortran/file-io.f
Normal 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
|
||||
15
Task/File-IO/GAP/file-io.gap
Normal file
15
Task/File-IO/GAP/file-io.gap
Normal 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;
|
||||
1
Task/File-IO/GML/file-io.gml
Normal file
1
Task/File-IO/GML/file-io.gml
Normal file
|
|
@ -0,0 +1 @@
|
|||
file_copy("input.txt","output.txt")
|
||||
2
Task/File-IO/GUISS/file-io.guiss
Normal file
2
Task/File-IO/GUISS/file-io.guiss
Normal 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]
|
||||
17
Task/File-IO/Go/file-io-1.go
Normal file
17
Task/File-IO/Go/file-io-1.go
Normal 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)
|
||||
}
|
||||
}
|
||||
37
Task/File-IO/Go/file-io-2.go
Normal file
37
Task/File-IO/Go/file-io-2.go
Normal 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)
|
||||
}
|
||||
}
|
||||
1
Task/File-IO/Groovy/file-io-1.groovy
Normal file
1
Task/File-IO/Groovy/file-io-1.groovy
Normal file
|
|
@ -0,0 +1 @@
|
|||
new File('output.txt').write(new File('input.txt').text)
|
||||
1
Task/File-IO/Groovy/file-io-2.groovy
Normal file
1
Task/File-IO/Groovy/file-io-2.groovy
Normal file
|
|
@ -0,0 +1 @@
|
|||
new AntBuilder().copy(file:'input.txt', toFile:'output.txt', overwrite:true)
|
||||
3
Task/File-IO/Groovy/file-io-3.groovy
Normal file
3
Task/File-IO/Groovy/file-io-3.groovy
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
new File('output.txt').withWriter( w ->
|
||||
new File('input.txt').withReader( r -> w << r }
|
||||
}
|
||||
1
Task/File-IO/Haskell/file-io.hs
Normal file
1
Task/File-IO/Haskell/file-io.hs
Normal file
|
|
@ -0,0 +1 @@
|
|||
main = readFile "input.txt" >>= writeFile "output.txt"
|
||||
2
Task/File-IO/HicEst/file-io-1.hicest
Normal file
2
Task/File-IO/HicEst/file-io-1.hicest
Normal 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)
|
||||
7
Task/File-IO/HicEst/file-io-2.hicest
Normal file
7
Task/File-IO/HicEst/file-io-2.hicest
Normal 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)
|
||||
5
Task/File-IO/HicEst/file-io-3.hicest
Normal file
5
Task/File-IO/HicEst/file-io-3.hicest
Normal 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
|
||||
12
Task/File-IO/IDL/file-io.idl
Normal file
12
Task/File-IO/IDL/file-io.idl
Normal 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
|
||||
5
Task/File-IO/Icon/file-io.icon
Normal file
5
Task/File-IO/Icon/file-io.icon
Normal 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
|
||||
9
Task/File-IO/Io/file-io.io
Normal file
9
Task/File-IO/Io/file-io.io
Normal 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
|
||||
1
Task/File-IO/J/file-io-1.j
Normal file
1
Task/File-IO/J/file-io-1.j
Normal file
|
|
@ -0,0 +1 @@
|
|||
'output.txt' (1!:2~ 1!:1)&< 'input.txt'
|
||||
2
Task/File-IO/J/file-io-2.j
Normal file
2
Task/File-IO/J/file-io-2.j
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
require 'files'
|
||||
'output.txt' (fwrite~ fread) 'input.txt'
|
||||
18
Task/File-IO/Java/file-io-1.java
Normal file
18
Task/File-IO/Java/file-io-1.java
Normal 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();
|
||||
}
|
||||
}
|
||||
}
|
||||
30
Task/File-IO/Java/file-io-2.java
Normal file
30
Task/File-IO/Java/file-io-2.java
Normal 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();
|
||||
}
|
||||
}
|
||||
}
|
||||
26
Task/File-IO/Java/file-io-3.java
Normal file
26
Task/File-IO/Java/file-io-3.java
Normal 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
|
||||
}
|
||||
}
|
||||
}
|
||||
14
Task/File-IO/Java/file-io-4.java
Normal file
14
Task/File-IO/Java/file-io-4.java
Normal 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();
|
||||
}
|
||||
}
|
||||
9
Task/File-IO/Java/file-io-5.java
Normal file
9
Task/File-IO/Java/file-io-5.java
Normal 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);
|
||||
}
|
||||
}
|
||||
15
Task/File-IO/JavaScript/file-io-1.js
Normal file
15
Task/File-IO/JavaScript/file-io-1.js
Normal 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();
|
||||
2
Task/File-IO/JavaScript/file-io-2.js
Normal file
2
Task/File-IO/JavaScript/file-io-2.js
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
var fs = require('fs');
|
||||
require('util').pump(fs.createReadStream('input.txt', {flags:'r'}), fs.createWriteStream('output.txt', {flags:'w+'}));
|
||||
1
Task/File-IO/K/file-io.k
Normal file
1
Task/File-IO/K/file-io.k
Normal file
|
|
@ -0,0 +1 @@
|
|||
`output.txt 0:0:`input.txt
|
||||
7
Task/File-IO/Lang5/file-io.lang5
Normal file
7
Task/File-IO/Lang5/file-io.lang5
Normal 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
|
||||
12
Task/File-IO/Liberty-BASIC/file-io.liberty
Normal file
12
Task/File-IO/Liberty-BASIC/file-io.liberty
Normal 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
|
||||
32
Task/File-IO/Lisaac/file-io.lisaac
Normal file
32
Task/File-IO/Lisaac/file-io.lisaac
Normal 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;
|
||||
};
|
||||
};
|
||||
};
|
||||
);
|
||||
10
Task/File-IO/Logo/file-io.logo
Normal file
10
Task/File-IO/Logo/file-io.logo
Normal 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
|
||||
12
Task/File-IO/Lua/file-io.lua
Normal file
12
Task/File-IO/Lua/file-io.lua
Normal 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"))
|
||||
8
Task/File-IO/MAXScript/file-io.max
Normal file
8
Task/File-IO/MAXScript/file-io.max
Normal 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
|
||||
3
Task/File-IO/Mathematica/file-io.mathematica
Normal file
3
Task/File-IO/Mathematica/file-io.mathematica
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
SetDirectory@NotebookDirectory[];
|
||||
If[FileExistsQ["output.txt"], DeleteFile["output.txt"], Print["No output yet"] ];
|
||||
CopyFile["input.txt", "output.txt"]
|
||||
19
Task/File-IO/Modula-3/file-io.mod3
Normal file
19
Task/File-IO/Modula-3/file-io.mod3
Normal 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.
|
||||
18
Task/File-IO/PHP/file-io-1.php
Normal file
18
Task/File-IO/PHP/file-io-1.php
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
<?php
|
||||
|
||||
if (!$in = fopen('input.txt', 'r')) {
|
||||
die('Could not open input file.');
|
||||
}
|
||||
|
||||
if (!$out = fopen('output.txt', 'w')) {
|
||||
die('Could not open output file.');
|
||||
}
|
||||
|
||||
while (!feof($in)) {
|
||||
$data = fread($in, 512);
|
||||
fwrite($out, $data);
|
||||
}
|
||||
|
||||
fclose($out);
|
||||
fclose($in);
|
||||
?>
|
||||
9
Task/File-IO/PHP/file-io-2.php
Normal file
9
Task/File-IO/PHP/file-io-2.php
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
<?php
|
||||
if ($contents = file_get_contents('input.txt')) {
|
||||
if (!file_put_contents('output.txt', $contents)) {
|
||||
echo('Could not write output file.');
|
||||
}
|
||||
} else {
|
||||
echo('Could not open input file.');
|
||||
}
|
||||
?>
|
||||
18
Task/File-IO/Perl/file-io.pl
Normal file
18
Task/File-IO/Perl/file-io.pl
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
#!/usr/bin/perl
|
||||
|
||||
open my $fh_in, '<', 'input.txt' or die "could not open <input.txt> for reading: $!";
|
||||
open my $fh_out, '>', 'output.txt' or die "could not open <output.txt> for writing: $!";
|
||||
# '>' overwrites file, '>>' appends to file, just like in the shell
|
||||
|
||||
binmode $fh_out; # marks filehandle for binary content on systems where that matters
|
||||
|
||||
print $fh_out $_ while <$fh_in>;
|
||||
# prints current line to file associated with $fh_out filehandle
|
||||
|
||||
# the same, less concise
|
||||
#while (<$fh_in>) {
|
||||
# print $fh_out $_;
|
||||
#};
|
||||
|
||||
close $fh_in;
|
||||
close $fh_out;
|
||||
2
Task/File-IO/PicoLisp/file-io-1.l
Normal file
2
Task/File-IO/PicoLisp/file-io-1.l
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
(let V (in "input.txt" (till))
|
||||
(out "output.txt" (prin V)) )
|
||||
3
Task/File-IO/PicoLisp/file-io-2.l
Normal file
3
Task/File-IO/PicoLisp/file-io-2.l
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
(in "input.txt"
|
||||
(out "output.txt"
|
||||
(echo) ) )
|
||||
2
Task/File-IO/Python/file-io-1.py
Normal file
2
Task/File-IO/Python/file-io-1.py
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
import shutil
|
||||
shutil.copyfile('input.txt', 'output.txt')
|
||||
6
Task/File-IO/Python/file-io-2.py
Normal file
6
Task/File-IO/Python/file-io-2.py
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
infile = open('input.txt', 'r')
|
||||
outfile = open('output.txt', 'w')
|
||||
for line in infile:
|
||||
outfile.write(line)
|
||||
outfile.close()
|
||||
infile.close()
|
||||
20
Task/File-IO/Python/file-io-3.py
Normal file
20
Task/File-IO/Python/file-io-3.py
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
import sys
|
||||
try:
|
||||
infile = open('input.txt', 'r')
|
||||
except IOError:
|
||||
print >> sys.stderr, "Unable to open input.txt for input"
|
||||
sys.exit(1)
|
||||
try:
|
||||
outfile = open('output.txt', 'w')
|
||||
except IOError:
|
||||
print >> sys.stderr, "Unable to open output.txt for output"
|
||||
sys.exit(1)
|
||||
try: # for finally
|
||||
try: # for I/O
|
||||
for line in infile:
|
||||
outfile.write(line)
|
||||
except IOError, e:
|
||||
print >> sys.stderr, "Some I/O Error occurred (reading from input.txt or writing to output.txt)"
|
||||
finally:
|
||||
infile.close()
|
||||
outfile.close()
|
||||
9
Task/File-IO/Python/file-io-4.py
Normal file
9
Task/File-IO/Python/file-io-4.py
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
import sys
|
||||
try:
|
||||
with open('input.txt') as infile:
|
||||
with open('output.txt', 'w') as outfile:
|
||||
for line in infile:
|
||||
outfile.write(line)
|
||||
except IOError:
|
||||
print >> sys.stderr, "Some I/O Error occurred"
|
||||
sys.exit(1)
|
||||
6
Task/File-IO/R/file-io-1.r
Normal file
6
Task/File-IO/R/file-io-1.r
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
src <- file("input.txt", "r")
|
||||
dest <- file("output.txt", "w")
|
||||
|
||||
fc <- readLines(src, -1)
|
||||
writeLines(fc, dest)
|
||||
close(src); close(dest)
|
||||
7
Task/File-IO/R/file-io-2.r
Normal file
7
Task/File-IO/R/file-io-2.r
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
src <- file("input.txt", "rb")
|
||||
dest <- file("output.txt", "wb")
|
||||
|
||||
while( length(v <- readBin(src, "raw")) > 0 ) {
|
||||
writeBin(v, dest)
|
||||
}
|
||||
close(src); close(dest)
|
||||
1
Task/File-IO/R/file-io-3.r
Normal file
1
Task/File-IO/R/file-io-3.r
Normal file
|
|
@ -0,0 +1 @@
|
|||
file.copy("input.txt", "output.txt", overwrite = FALSE)
|
||||
11
Task/File-IO/REXX/file-io-1.rexx
Normal file
11
Task/File-IO/REXX/file-io-1.rexx
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
/*REXX program to read a file and store the contents into an output file*/
|
||||
|
||||
ifid = 'input.txt' /*name of the input file. */
|
||||
ofid = 'output.txt' /*name of the output file. */
|
||||
call lineout ofid,,1 /*insure output starts at line 1.*/
|
||||
|
||||
do while lines(ifid)\==0 /*read until finished. */
|
||||
y = linein(ifid) /*read a record from input. */
|
||||
call lineout ofid,y /*write a record to output.nt. */
|
||||
end
|
||||
/*stick a fork in it, we're done.*/
|
||||
11
Task/File-IO/REXX/file-io-2.rexx
Normal file
11
Task/File-IO/REXX/file-io-2.rexx
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
/*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.)*/
|
||||
|
||||
ifid = 'input.txt' /*name of the input file. */
|
||||
ofid = 'output.txt' /*name of the output file. */
|
||||
call lineout ofid,,1 /*insure output starts at line 1.*/
|
||||
|
||||
do while lines(ifid)\==0 /*read until finished. */
|
||||
call lineout ofid, linein(ifid) /*read & write in one statement. */
|
||||
end /*while*/
|
||||
/*stick a fork in it, we're done.*/
|
||||
8
Task/File-IO/REXX/file-io-3.rexx
Normal file
8
Task/File-IO/REXX/file-io-3.rexx
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
/*REXX program to read a file and write contents to an output file*****
|
||||
* 03.09.2012 Walter Pachl (without erase string would be appended)
|
||||
**********************************************************************/
|
||||
ifid='input.txt' /*name of the input file. */
|
||||
ofid='output.txt' /*name of the output file. */
|
||||
'erase' ofid /* avoid appending */
|
||||
s=charin(ifid,,1000000) /* read the input file */
|
||||
Call charout ofid,s /* write to output file */
|
||||
Some files were not shown because too many files have changed in this diff Show more
Loading…
Add table
Add a link
Reference in a new issue