Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
3
Task/Write-entire-file/00-META.yaml
Normal file
3
Task/Write-entire-file/00-META.yaml
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
---
|
||||
from: http://rosettacode.org/wiki/Write_entire_file
|
||||
note: File handling
|
||||
7
Task/Write-entire-file/00-TASK.txt
Normal file
7
Task/Write-entire-file/00-TASK.txt
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
;Task:
|
||||
(Over)write a file so that it contains a string.
|
||||
|
||||
|
||||
The reverse of [[Read entire file]]—for when you want to update or create a file which you would read in its entirety all at once.
|
||||
<br><br>
|
||||
|
||||
1
Task/Write-entire-file/11l/write-entire-file.11l
Normal file
1
Task/Write-entire-file/11l/write-entire-file.11l
Normal file
|
|
@ -0,0 +1 @@
|
|||
File(filename, ‘w’).write(string)
|
||||
|
|
@ -0,0 +1,89 @@
|
|||
/* ARM assembly AARCH64 Raspberry PI 3B */
|
||||
/* program writeFile64.s */
|
||||
|
||||
/*******************************************/
|
||||
/* Constantes file */
|
||||
/*******************************************/
|
||||
/* for this file see task include a file in language AArch64 assembly*/
|
||||
.include "../includeConstantesARM64.inc"
|
||||
|
||||
/*********************************/
|
||||
/* Initialized data */
|
||||
/*********************************/
|
||||
.data
|
||||
szMessErreur: .asciz "Error open file.\n"
|
||||
szMessErreur1: .asciz "Error close file.\n"
|
||||
szMessErreur2: .asciz "Error write file.\n"
|
||||
szMessWriteOK: .asciz "String write in file OK.\n"
|
||||
|
||||
szParamNom: .asciz "./fic1.txt" // file name
|
||||
sZoneEcrit: .ascii "(Over)write a file so that it contains a string."
|
||||
.equ LGZONEECRIT, . - sZoneEcrit
|
||||
/*********************************/
|
||||
/* UnInitialized data */
|
||||
/*********************************/
|
||||
.bss
|
||||
|
||||
/*********************************/
|
||||
/* code section */
|
||||
/*********************************/
|
||||
.text
|
||||
.global main
|
||||
main: // entry of program
|
||||
// file open
|
||||
mov x0,AT_FDCWD // current directory
|
||||
ldr x1,qAdrszParamNom // filename
|
||||
mov x2,O_CREAT|O_WRONLY // flags
|
||||
ldr x3,oficmask1 // mode
|
||||
mov x8,OPEN // Linux call system
|
||||
svc 0 //
|
||||
cmp x0,0 // error ?
|
||||
ble erreur // yes
|
||||
mov x28,x0 // save File Descriptor
|
||||
// x0 = FD
|
||||
ldr x1,qAdrsZoneEcrit // write string address
|
||||
mov x2,LGZONEECRIT // string size
|
||||
mov x8,WRITE // Linux call system
|
||||
svc 0
|
||||
cmp x0,0 // error ?
|
||||
ble erreur2 // yes
|
||||
// close file
|
||||
mov x0,x28 // File Descriptor
|
||||
mov x8,CLOSE // Linuc call system
|
||||
svc 0
|
||||
cmp x0,0 // error ?
|
||||
blt erreur1
|
||||
ldr x0,qAdrszMessWriteOK
|
||||
bl affichageMess
|
||||
mov x0,#0 // return code OK
|
||||
b 100f
|
||||
erreur:
|
||||
ldr x1,qAdrszMessErreur
|
||||
bl affichageMess // display error message
|
||||
mov x0,#1
|
||||
b 100f
|
||||
erreur1:
|
||||
ldr x1,qAdrszMessErreur1 // x0 <- adresse chaine
|
||||
bl affichageMess // display error message
|
||||
mov x0,#1 // return code error
|
||||
b 100f
|
||||
erreur2:
|
||||
ldr x0,qAdrszMessErreur2
|
||||
bl affichageMess // display error message
|
||||
mov x0,#1 // return code error
|
||||
b 100f
|
||||
100: // program end
|
||||
mov x8,EXIT
|
||||
svc #0
|
||||
qAdrszParamNom: .quad szParamNom
|
||||
qAdrszMessErreur: .quad szMessErreur
|
||||
qAdrszMessErreur1: .quad szMessErreur1
|
||||
qAdrszMessErreur2: .quad szMessErreur2
|
||||
qAdrszMessWriteOK: .quad szMessWriteOK
|
||||
qAdrsZoneEcrit: .quad sZoneEcrit
|
||||
oficmask1: .quad 0644 // this zone is Octal number (0 before)
|
||||
/********************************************************/
|
||||
/* File Include fonctions */
|
||||
/********************************************************/
|
||||
/* for this file see task include a file in language AArch64 assembly */
|
||||
.include "../includeARM64.inc"
|
||||
11
Task/Write-entire-file/ALGOL-68/write-entire-file.alg
Normal file
11
Task/Write-entire-file/ALGOL-68/write-entire-file.alg
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
IF FILE output;
|
||||
STRING output file name = "output.txt";
|
||||
open( output, output file name, stand out channel ) = 0
|
||||
THEN
|
||||
# file opened OK #
|
||||
put( output, ( "line 1", newline, "line 2", newline ) );
|
||||
close( output )
|
||||
ELSE
|
||||
# unable to open the output file #
|
||||
print( ( "Cannot open ", output file name, newline ) )
|
||||
FI
|
||||
7
Task/Write-entire-file/AWK/write-entire-file.awk
Normal file
7
Task/Write-entire-file/AWK/write-entire-file.awk
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
# syntax: GAWK -f WRITE_ENTIRE_FILE.AWK
|
||||
BEGIN {
|
||||
dev = "FILENAME.TXT"
|
||||
print("(Over)write a file so that it contains a string.") >dev
|
||||
close(dev)
|
||||
exit(0)
|
||||
}
|
||||
5
Task/Write-entire-file/Action-/write-entire-file.action
Normal file
5
Task/Write-entire-file/Action-/write-entire-file.action
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
proc MAIN()
|
||||
open (1,"D:FILE.TXT",8,0)
|
||||
printde(1,"My string")
|
||||
close(1)
|
||||
return
|
||||
18
Task/Write-entire-file/Ada/write-entire-file.ada
Normal file
18
Task/Write-entire-file/Ada/write-entire-file.ada
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
with Ada.Text_IO; use Ada.Text_IO;
|
||||
|
||||
procedure Write_Whole_File is
|
||||
File_Name : constant String := "the_file.txt";
|
||||
|
||||
F : File_Type;
|
||||
begin
|
||||
begin
|
||||
Open (F, Mode => Out_File, Name => File_Name);
|
||||
exception
|
||||
when Name_Error => Create (F, Mode => Out_File, Name => File_Name);
|
||||
end;
|
||||
|
||||
Put (F, "(Over)write a file so that it contains a string. " &
|
||||
"The reverse of Read entire file—for when you want to update or " &
|
||||
"create a file which you would read in its entirety all at once.");
|
||||
Close (F);
|
||||
end Write_Whole_File;
|
||||
|
|
@ -0,0 +1,9 @@
|
|||
10 D$ = CHR$ (4)
|
||||
20 F$ = "OUTPUT.TXT"
|
||||
30 PRINT D$"OPEN"F$
|
||||
40 PRINT D$"CLOSE"F$
|
||||
50 PRINT D$"DELETE"F$
|
||||
60 PRINT D$"OPEN"F$
|
||||
70 PRINT D$"WRITE"F$
|
||||
80 PRINT "THIS STRING IS TO BE WRITTEN TO THE FILE"
|
||||
90 PRINT D$"CLOSE"F$
|
||||
2
Task/Write-entire-file/Arturo/write-entire-file.arturo
Normal file
2
Task/Write-entire-file/Arturo/write-entire-file.arturo
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
contents: "Hello World!"
|
||||
write "output.txt" contents
|
||||
3
Task/Write-entire-file/AutoHotkey/write-entire-file.ahk
Normal file
3
Task/Write-entire-file/AutoHotkey/write-entire-file.ahk
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
file := FileOpen("test.txt", "w")
|
||||
file.Write("this is a test string")
|
||||
file.Close()
|
||||
4
Task/Write-entire-file/BASIC256/write-entire-file.basic
Normal file
4
Task/Write-entire-file/BASIC256/write-entire-file.basic
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
f = freefile
|
||||
open f, "output.txt"
|
||||
write f, "This string is to be written to the file"
|
||||
close f
|
||||
3
Task/Write-entire-file/BBC-BASIC/write-entire-file.basic
Normal file
3
Task/Write-entire-file/BBC-BASIC/write-entire-file.basic
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
file% = OPENOUT filename$
|
||||
PRINT#file%, text$
|
||||
CLOSE#file%
|
||||
1
Task/Write-entire-file/BaCon/write-entire-file-1.bacon
Normal file
1
Task/Write-entire-file/BaCon/write-entire-file-1.bacon
Normal file
|
|
@ -0,0 +1 @@
|
|||
SAVE s$ TO filename$
|
||||
1
Task/Write-entire-file/BaCon/write-entire-file-2.bacon
Normal file
1
Task/Write-entire-file/BaCon/write-entire-file-2.bacon
Normal file
|
|
@ -0,0 +1 @@
|
|||
BSAVE mem TO filename$ SIZE n
|
||||
1
Task/Write-entire-file/Bracmat/write-entire-file.bracmat
Normal file
1
Task/Write-entire-file/Bracmat/write-entire-file.bracmat
Normal file
|
|
@ -0,0 +1 @@
|
|||
put$("(Over)write a file so that it contains a string.",file,NEW)
|
||||
10
Task/Write-entire-file/C++/write-entire-file.cpp
Normal file
10
Task/Write-entire-file/C++/write-entire-file.cpp
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
#include <fstream>
|
||||
using namespace std;
|
||||
|
||||
int main()
|
||||
{
|
||||
ofstream file("new.txt");
|
||||
file << "this is a string";
|
||||
file.close();
|
||||
return 0;
|
||||
}
|
||||
1
Task/Write-entire-file/C-sharp/write-entire-file.cs
Normal file
1
Task/Write-entire-file/C-sharp/write-entire-file.cs
Normal file
|
|
@ -0,0 +1 @@
|
|||
System.IO.File.WriteAllText("filename.txt", "This file contains a string.");
|
||||
11
Task/Write-entire-file/C/write-entire-file-1.c
Normal file
11
Task/Write-entire-file/C/write-entire-file-1.c
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
/*
|
||||
* Write Entire File -- RossetaCode -- dirty hackish solution
|
||||
*/
|
||||
#define _CRT_SECURE_NO_WARNINGS // turn off MS Visual Studio restrictions
|
||||
#include <stdio.h>
|
||||
|
||||
int main(void)
|
||||
{
|
||||
return 0 >= fputs("ANY STRING TO WRITE TO A FILE AT ONCE.",
|
||||
freopen("sample.txt","wb",stdout));
|
||||
}
|
||||
97
Task/Write-entire-file/C/write-entire-file-2.c
Normal file
97
Task/Write-entire-file/C/write-entire-file-2.c
Normal file
|
|
@ -0,0 +1,97 @@
|
|||
/*
|
||||
* Write Entire File -- RossetaCode -- ASCII version with BUFFERED files
|
||||
*/
|
||||
|
||||
#define _CRT_SECURE_NO_WARNINGS
|
||||
|
||||
#include <assert.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
/**
|
||||
* Write entire file at once.
|
||||
*
|
||||
* @param fileName file name
|
||||
* @param data buffer with data
|
||||
* @param size number of bytes to write
|
||||
*
|
||||
* @return Number of bytes have been written.
|
||||
*/
|
||||
int writeEntireFile(char* fileName, const void* data, size_t size)
|
||||
{
|
||||
size_t numberBytesWritten = 0; // will be updated
|
||||
|
||||
// Notice: assertions can be turned off by #define NDEBUG
|
||||
//
|
||||
assert( fileName != NULL );
|
||||
assert( data != NULL );
|
||||
assert( size > 0 );
|
||||
|
||||
// Check for a null pointer or an empty file name.
|
||||
//
|
||||
// BTW, should we write if ( ptr != NULL) or simply if ( ptr ) ?
|
||||
// Both of these forms are correct. At issue is which is more readable.
|
||||
//
|
||||
if ( fileName != NULL && *fileName != '\0' )
|
||||
{
|
||||
// Try to open file in BINARY MODE
|
||||
//
|
||||
FILE* file = fopen(fileName,"wb");
|
||||
|
||||
// There is a possibility to allocate a big buffer to speed up i/o ops:
|
||||
//
|
||||
// const size_t BIG_BUFFER_SIZE = 0x20000; // 128KiB
|
||||
// void* bigBuffer = malloc(BIG_BUFFER_SIZE);
|
||||
// if ( bigBuffer != NULL )
|
||||
// {
|
||||
// setvbuf(file,bigBuffer,_IOFBF,BIG_BUFFER_SIZE);
|
||||
// }
|
||||
//
|
||||
// Of course, you should release the malloc allocated buffer somewhere.
|
||||
// Otherwise, bigBuffer will be released after the end of the program.
|
||||
|
||||
|
||||
if ( file != NULL )
|
||||
{
|
||||
// Return value from fwrite( data, 1, size, file ) is the number
|
||||
// of bytes written. Return value from fwrite( data, size, 1, file )
|
||||
// is the number of blocks (either 0 or 1) written.
|
||||
//
|
||||
// Notice, that write (see io.h) is less capable than fwrite.
|
||||
//
|
||||
|
||||
if ( data != NULL )
|
||||
{
|
||||
numberBytesWritten = fwrite( data, 1, size, file );
|
||||
}
|
||||
fclose( file );
|
||||
}
|
||||
}
|
||||
return numberBytesWritten;
|
||||
}
|
||||
|
||||
#define DATA_LENGTH 8192 /* 8KiB */
|
||||
|
||||
int main(void)
|
||||
{
|
||||
// Large arrays can exhaust memory on the stack. This is why the static
|
||||
// keyword is used.Static variables are allocated outside the stack.
|
||||
//
|
||||
static char data[DATA_LENGTH];
|
||||
|
||||
// Filling data array with 'A' character.
|
||||
// Of course, you can use any other data here.
|
||||
//
|
||||
int i;
|
||||
for ( i = 0; i < DATA_LENGTH; i++ )
|
||||
{
|
||||
data[i] = 'A';
|
||||
}
|
||||
|
||||
// Write entire file at once.
|
||||
//
|
||||
if ( writeEntireFile("sample.txt", data, DATA_LENGTH ) == DATA_LENGTH )
|
||||
return EXIT_SUCCESS;
|
||||
else
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
66
Task/Write-entire-file/C/write-entire-file-3.c
Normal file
66
Task/Write-entire-file/C/write-entire-file-3.c
Normal file
|
|
@ -0,0 +1,66 @@
|
|||
/*
|
||||
* Write Entire File -- RossetaCode -- plain POSIX write() from io.h
|
||||
*/
|
||||
|
||||
#define _CRT_SECURE_NO_WARNINGS // turn off MS Visual Studio restrictions
|
||||
#define _CRT_NONSTDC_NO_WARNINGS // turn off MS Visual Studio restrictions
|
||||
|
||||
#include <assert.h>
|
||||
#include <fcntl.h>
|
||||
#include <io.h>
|
||||
|
||||
/**
|
||||
* Write entire file at once.
|
||||
*
|
||||
* @param fileName file name
|
||||
* @param data buffer with data
|
||||
* @param size number of bytes to write
|
||||
*
|
||||
* @return Number of bytes have been written.
|
||||
*/
|
||||
int writeEntireFile(char* fileName, const void* data, size_t size)
|
||||
{
|
||||
size_t numberBytesWritten = 0; // will be updated
|
||||
int file; // file handle is an integer (see Fortran ;)
|
||||
|
||||
// Notice: we can not trust in assertions to work.
|
||||
// Assertions can be turned off by #define NDEBUG.
|
||||
//
|
||||
assert( fileName );
|
||||
assert( data );
|
||||
assert( size > 0 );
|
||||
|
||||
if(fileName && fileName[0] && (file=open(fileName,O_CREAT|O_BINARY|O_WRONLY))!=(-1))
|
||||
{
|
||||
if ( data )
|
||||
numberBytesWritten = write( file, data, size );
|
||||
close( file );
|
||||
}
|
||||
return numberBytesWritten;
|
||||
}
|
||||
|
||||
#define DATA_LENGTH 8192 /* 8KiB */
|
||||
|
||||
int main(void)
|
||||
{
|
||||
// Large arrays can exhaust memory on the stack. This is why the static
|
||||
// keyword is used.Static variables are allocated outside the stack.
|
||||
//
|
||||
static char data[DATA_LENGTH];
|
||||
|
||||
// Filling data array with 'Z' character.
|
||||
// Of course, you can use any other data here.
|
||||
//
|
||||
int i;
|
||||
for ( i = 0; i < DATA_LENGTH; i++ )
|
||||
{
|
||||
data[i] = 'Z';
|
||||
}
|
||||
|
||||
// Write entire file at once.
|
||||
//
|
||||
if ( writeEntireFile("sample.txt", data, DATA_LENGTH ) == DATA_LENGTH )
|
||||
return 0;
|
||||
else
|
||||
return 1;
|
||||
}
|
||||
41
Task/Write-entire-file/COBOL/write-entire-file.cobol
Normal file
41
Task/Write-entire-file/COBOL/write-entire-file.cobol
Normal file
|
|
@ -0,0 +1,41 @@
|
|||
IDENTIFICATION DIVISION.
|
||||
PROGRAM-ID. Overwrite.
|
||||
AUTHOR. Bill Gunshannon.
|
||||
INSTALLATION. Home.
|
||||
DATE-WRITTEN. 31 December 2021.
|
||||
************************************************************
|
||||
** Program Abstract:
|
||||
** Simple COBOL task. Open file for output. Write
|
||||
** data to file. Close file. Done...
|
||||
************************************************************
|
||||
|
||||
ENVIRONMENT DIVISION.
|
||||
|
||||
INPUT-OUTPUT SECTION.
|
||||
FILE-CONTROL.
|
||||
SELECT File-Name ASSIGN TO "File.txt"
|
||||
ORGANIZATION IS LINE SEQUENTIAL.
|
||||
DATA DIVISION.
|
||||
|
||||
FILE SECTION.
|
||||
|
||||
FD File-Name
|
||||
DATA RECORD IS Record-Name.
|
||||
01 Record-Name.
|
||||
02 Field1 PIC X(80).
|
||||
|
||||
WORKING-STORAGE SECTION.
|
||||
|
||||
01 New-Val PIC X(80)
|
||||
VALUE 'Hello World'.
|
||||
|
||||
|
||||
PROCEDURE DIVISION.
|
||||
|
||||
Main-Program.
|
||||
OPEN OUTPUT File-Name.
|
||||
WRITE Record-Name FROM New-Val.
|
||||
CLOSE File-Name.
|
||||
STOP RUN.
|
||||
|
||||
END-PROGRAM.
|
||||
1
Task/Write-entire-file/Clojure/write-entire-file.clj
Normal file
1
Task/Write-entire-file/Clojure/write-entire-file.clj
Normal file
|
|
@ -0,0 +1 @@
|
|||
(spit "file.txt" "this is a string")
|
||||
|
|
@ -0,0 +1,5 @@
|
|||
(with-open-file (str "filename.txt"
|
||||
:direction :output
|
||||
:if-exists :supersede
|
||||
:if-does-not-exist :create)
|
||||
(format str "File content...~%"))
|
||||
6
Task/Write-entire-file/D/write-entire-file.d
Normal file
6
Task/Write-entire-file/D/write-entire-file.d
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
import std.stdio;
|
||||
|
||||
void main() {
|
||||
auto file = File("new.txt", "wb");
|
||||
file.writeln("Hello World!");
|
||||
}
|
||||
10
Task/Write-entire-file/Delphi/write-entire-file.delphi
Normal file
10
Task/Write-entire-file/Delphi/write-entire-file.delphi
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
program Write_entire_file;
|
||||
|
||||
{$APPTYPE CONSOLE}
|
||||
|
||||
uses
|
||||
System.IoUtils;
|
||||
|
||||
begin
|
||||
TFile.WriteAllText('filename.txt', 'This file contains a string.');
|
||||
end.
|
||||
6
Task/Write-entire-file/Elena/write-entire-file.elena
Normal file
6
Task/Write-entire-file/Elena/write-entire-file.elena
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
import system'io;
|
||||
|
||||
public program()
|
||||
{
|
||||
File.assign("filename.txt").saveContent("This file contains a string.")
|
||||
}
|
||||
1
Task/Write-entire-file/Elixir/write-entire-file.elixir
Normal file
1
Task/Write-entire-file/Elixir/write-entire-file.elixir
Normal file
|
|
@ -0,0 +1 @@
|
|||
File.write("file.txt", string)
|
||||
1
Task/Write-entire-file/F-Sharp/write-entire-file.fs
Normal file
1
Task/Write-entire-file/F-Sharp/write-entire-file.fs
Normal file
|
|
@ -0,0 +1 @@
|
|||
System.IO.File.WriteAllText("filename.txt", "This file contains a string.")
|
||||
2
Task/Write-entire-file/Factor/write-entire-file.factor
Normal file
2
Task/Write-entire-file/Factor/write-entire-file.factor
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
USING: io.encodings.utf8 io.files ;
|
||||
"this is a string" "file.txt" utf8 set-file-contents
|
||||
3
Task/Write-entire-file/Fortran/write-entire-file.f
Normal file
3
Task/Write-entire-file/Fortran/write-entire-file.f
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
OPEN (F,FILE="SomeFileName.txt",STATUS="REPLACE")
|
||||
WRITE (F,*) "Whatever you like."
|
||||
WRITE (F) BIGARRAY
|
||||
20
Task/Write-entire-file/Free-Pascal/write-entire-file.pas
Normal file
20
Task/Write-entire-file/Free-Pascal/write-entire-file.pas
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
program overwriteFile(input, output, stdErr);
|
||||
{$mode objFPC} // for exception treatment
|
||||
uses
|
||||
sysUtils; // for applicationName, getTempDir, getTempFileName
|
||||
// also: importing sysUtils converts all run-time errors to exceptions
|
||||
resourcestring
|
||||
hooray = 'Hello world!';
|
||||
var
|
||||
FD: text;
|
||||
begin
|
||||
// on a Debian GNU/Linux distribution,
|
||||
// this will write to /tmp/overwriteFile00000.tmp (or alike)
|
||||
assign(FD, getTempFileName(getTempDir(false), applicationName()));
|
||||
try
|
||||
rewrite(FD); // could fail, if user has no permission to write
|
||||
writeLn(FD, hooray);
|
||||
finally
|
||||
close(FD);
|
||||
end;
|
||||
end.
|
||||
5
Task/Write-entire-file/FreeBASIC/write-entire-file.basic
Normal file
5
Task/Write-entire-file/FreeBASIC/write-entire-file.basic
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
' FB 1.05.0 Win64
|
||||
|
||||
Open "output.txt" For Output As #1
|
||||
Print #1, "This is a string"
|
||||
Close #1
|
||||
3
Task/Write-entire-file/Frink/write-entire-file.frink
Normal file
3
Task/Write-entire-file/Frink/write-entire-file.frink
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
w = new Writer["test.txt"]
|
||||
w.print["I am the captain now."]
|
||||
w.close[]
|
||||
5
Task/Write-entire-file/Gambas/write-entire-file.gambas
Normal file
5
Task/Write-entire-file/Gambas/write-entire-file.gambas
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
Public Sub Main()
|
||||
|
||||
File.Save(User.home &/ "test.txt", "(Over)write a file so that it contains a string.")
|
||||
|
||||
End
|
||||
5
Task/Write-entire-file/Go/write-entire-file.go
Normal file
5
Task/Write-entire-file/Go/write-entire-file.go
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
import "io/ioutil"
|
||||
|
||||
func main() {
|
||||
ioutil.WriteFile("path/to/your.file", []byte("data"), 0644)
|
||||
}
|
||||
4
Task/Write-entire-file/Groovy/write-entire-file.groovy
Normal file
4
Task/Write-entire-file/Groovy/write-entire-file.groovy
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
new File("myFile.txt").text = """a big string
|
||||
that can be
|
||||
splitted over lines
|
||||
"""
|
||||
7
Task/Write-entire-file/Haskell/write-entire-file.hs
Normal file
7
Task/Write-entire-file/Haskell/write-entire-file.hs
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
main :: IO ( )
|
||||
main = do
|
||||
putStrLn "Enter a string!"
|
||||
str <- getLine
|
||||
putStrLn "Where do you want to store this string ?"
|
||||
myFile <- getLine
|
||||
appendFile myFile str
|
||||
1
Task/Write-entire-file/J/write-entire-file-1.j
Normal file
1
Task/Write-entire-file/J/write-entire-file-1.j
Normal file
|
|
@ -0,0 +1 @@
|
|||
characters fwrite filename
|
||||
1
Task/Write-entire-file/J/write-entire-file-2.j
Normal file
1
Task/Write-entire-file/J/write-entire-file-2.j
Normal file
|
|
@ -0,0 +1 @@
|
|||
characters 1!:2<filename
|
||||
10
Task/Write-entire-file/Java/write-entire-file-1.java
Normal file
10
Task/Write-entire-file/Java/write-entire-file-1.java
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
import java.io.*;
|
||||
|
||||
public class Test {
|
||||
|
||||
public static void main(String[] args) throws IOException {
|
||||
try (BufferedWriter bw = new BufferedWriter(new FileWriter("test.txt"))) {
|
||||
bw.write("abc");
|
||||
}
|
||||
}
|
||||
}
|
||||
15
Task/Write-entire-file/Java/write-entire-file-2.java
Normal file
15
Task/Write-entire-file/Java/write-entire-file-2.java
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
import java.io.IOException;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.StandardOpenOption;
|
||||
|
||||
public final class WriteEntireFile {
|
||||
|
||||
public static void main(String[] aArgs) throws IOException {
|
||||
String contents = "Hello World";
|
||||
String filePath = "output.txt";
|
||||
|
||||
Files.write(Path.of(filePath), contents.getBytes(), StandardOpenOption.CREATE);
|
||||
}
|
||||
|
||||
}
|
||||
7
Task/Write-entire-file/Julia/write-entire-file.julia
Normal file
7
Task/Write-entire-file/Julia/write-entire-file.julia
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
function writeFile(filename, data)
|
||||
f = open(filename, "w")
|
||||
write(f, data)
|
||||
close(f)
|
||||
end
|
||||
|
||||
writeFile("test.txt", "Hi there.")
|
||||
1
Task/Write-entire-file/K/write-entire-file.k
Normal file
1
Task/Write-entire-file/K/write-entire-file.k
Normal file
|
|
@ -0,0 +1 @@
|
|||
"example.txt" 0:"example file contents"
|
||||
8
Task/Write-entire-file/Kotlin/write-entire-file.kotlin
Normal file
8
Task/Write-entire-file/Kotlin/write-entire-file.kotlin
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
// version 1.1.2
|
||||
|
||||
import java.io.File
|
||||
|
||||
fun main(args: Array<String>) {
|
||||
val text = "empty vessels make most noise"
|
||||
File("output.txt").writeText(text)
|
||||
}
|
||||
20
Task/Write-entire-file/Lingo/write-entire-file.lingo
Normal file
20
Task/Write-entire-file/Lingo/write-entire-file.lingo
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
----------------------------------------
|
||||
-- Saves string as file
|
||||
-- @param {string} tFile
|
||||
-- @param {string} tString
|
||||
-- @return {bool} success
|
||||
----------------------------------------
|
||||
on writeFile (tFile, tString)
|
||||
fp = xtra("fileIO").new()
|
||||
fp.openFile(tFile, 2)
|
||||
err = fp.status()
|
||||
if not (err) then fp.delete()
|
||||
else if (err and not (err = -37)) then return false
|
||||
fp.createFile(tFile)
|
||||
if fp.status() then return false
|
||||
fp.openFile(tFile, 2)
|
||||
if fp.status() then return false
|
||||
fp.writeString(tString)
|
||||
fp.closeFile()
|
||||
return true
|
||||
end
|
||||
|
|
@ -0,0 +1 @@
|
|||
put "this is a string" into URL "file:~/Desktop/TestFile.txt"
|
||||
7
Task/Write-entire-file/Lua/write-entire-file.lua
Normal file
7
Task/Write-entire-file/Lua/write-entire-file.lua
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
function writeFile (filename, data)
|
||||
local f = io.open(filename, 'w')
|
||||
f:write(data)
|
||||
f:close()
|
||||
end
|
||||
|
||||
writeFile("stringFile.txt", "Mmm... stringy.")
|
||||
1
Task/Write-entire-file/Maple/write-entire-file.maple
Normal file
1
Task/Write-entire-file/Maple/write-entire-file.maple
Normal file
|
|
@ -0,0 +1 @@
|
|||
Export("directory/filename.txt", string);
|
||||
|
|
@ -0,0 +1 @@
|
|||
Export["filename.txt","contents string"]
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
import Nanoquery.IO
|
||||
|
||||
new(File, fname).create().write(string)
|
||||
1
Task/Write-entire-file/Nim/write-entire-file.nim
Normal file
1
Task/Write-entire-file/Nim/write-entire-file.nim
Normal file
|
|
@ -0,0 +1 @@
|
|||
writeFile("filename.txt", "An arbitrary string")
|
||||
10
Task/Write-entire-file/OCaml/write-entire-file.ocaml
Normal file
10
Task/Write-entire-file/OCaml/write-entire-file.ocaml
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
let write_file filename s =
|
||||
let oc = open_out filename in
|
||||
output_string oc s;
|
||||
close_out oc;
|
||||
;;
|
||||
|
||||
let () =
|
||||
let filename = "test.txt" in
|
||||
let s = String.init 26 (fun i -> char_of_int (i + int_of_char 'A')) in
|
||||
write_file filename s
|
||||
11
Task/Write-entire-file/Objeck/write-entire-file.objeck
Normal file
11
Task/Write-entire-file/Objeck/write-entire-file.objeck
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
use System.IO.File;
|
||||
|
||||
class WriteFile {
|
||||
function : Main(args : String[]) ~ Nil {
|
||||
writer ← FileWriter→New("test.txt");
|
||||
leaving {
|
||||
writer→Close();
|
||||
};
|
||||
writer→WriteString("this is a test string");
|
||||
}
|
||||
}
|
||||
1
Task/Write-entire-file/PHP/write-entire-file.php
Normal file
1
Task/Write-entire-file/PHP/write-entire-file.php
Normal file
|
|
@ -0,0 +1 @@
|
|||
file_put_contents($filename, $data)
|
||||
6
Task/Write-entire-file/Pascal/write-entire-file-1.pas
Normal file
6
Task/Write-entire-file/Pascal/write-entire-file-1.pas
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
{$ifDef FPC}{$mode ISO}{$endIf}
|
||||
program overwriteFile(FD);
|
||||
begin
|
||||
writeLn(FD, 'Whasup?');
|
||||
close(FD);
|
||||
end.
|
||||
1
Task/Write-entire-file/Pascal/write-entire-file-2.pas
Normal file
1
Task/Write-entire-file/Pascal/write-entire-file-2.pas
Normal file
|
|
@ -0,0 +1 @@
|
|||
./overwriteFile >&- <&- 0>/tmp/foo # open file descriptor with index 0 for writing
|
||||
2
Task/Write-entire-file/Perl/write-entire-file-1.pl
Normal file
2
Task/Write-entire-file/Perl/write-entire-file-1.pl
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
use File::Slurper 'write_text';
|
||||
write_text($filename, $data);
|
||||
2
Task/Write-entire-file/Perl/write-entire-file-2.pl
Normal file
2
Task/Write-entire-file/Perl/write-entire-file-2.pl
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
use Path::Tiny;
|
||||
path($filename)->spew_utf8($data);
|
||||
3
Task/Write-entire-file/Perl/write-entire-file-3.pl
Normal file
3
Task/Write-entire-file/Perl/write-entire-file-3.pl
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
open my $fh, '>:encoding(UTF-8)', $filename or die "Could not open '$filename': $!";
|
||||
print $fh $data;
|
||||
close $fh;
|
||||
5
Task/Write-entire-file/Phix/write-entire-file.phix
Normal file
5
Task/Write-entire-file/Phix/write-entire-file.phix
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
(notonline)-->
|
||||
<span style="color: #008080;">without</span> <span style="color: #008080;">js</span> <span style="color: #000080;font-style:italic;">-- (file i/o)</span>
|
||||
<span style="color: #004080;">integer</span> <span style="color: #000000;">res</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">write_lines</span><span style="color: #0000FF;">(</span><span style="color: #008000;">"file.txt"</span><span style="color: #0000FF;">,{</span><span style="color: #008000;">"line 1\nline 2"</span><span style="color: #0000FF;">})</span>
|
||||
<span style="color: #008080;">if</span> <span style="color: #000000;">res</span><span style="color: #0000FF;">=-</span><span style="color: #000000;">1</span> <span style="color: #008080;">then</span> <span style="color: #7060A8;">crash</span><span style="color: #0000FF;">(</span><span style="color: #008000;">"error"</span><span style="color: #0000FF;">)</span> <span style="color: #008080;">end</span> <span style="color: #008080;">if</span>
|
||||
<!--
|
||||
2
Task/Write-entire-file/PicoLisp/write-entire-file.l
Normal file
2
Task/Write-entire-file/PicoLisp/write-entire-file.l
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
(out "file.txt"
|
||||
(prinl "My string") )
|
||||
1
Task/Write-entire-file/Pike/write-entire-file.pike
Normal file
1
Task/Write-entire-file/Pike/write-entire-file.pike
Normal file
|
|
@ -0,0 +1 @@
|
|||
Stdio.write_file("file.txt", "My string");
|
||||
1
Task/Write-entire-file/PowerShell/write-entire-file.psh
Normal file
1
Task/Write-entire-file/PowerShell/write-entire-file.psh
Normal file
|
|
@ -0,0 +1 @@
|
|||
Get-Process | Out-File -FilePath .\ProcessList.txt
|
||||
16
Task/Write-entire-file/PureBasic/write-entire-file.basic
Normal file
16
Task/Write-entire-file/PureBasic/write-entire-file.basic
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
EnableExplicit
|
||||
|
||||
Define fOutput$ = "output.txt" ; enter path of file to create or overwrite
|
||||
Define str$ = "This string is to be written to the file"
|
||||
|
||||
If OpenConsole()
|
||||
If CreateFile(0, fOutput$)
|
||||
WriteString(0, str$)
|
||||
CloseFile(0)
|
||||
Else
|
||||
PrintN("Error creating or opening output file")
|
||||
EndIf
|
||||
PrintN("Press any key to close the console")
|
||||
Repeat: Delay(10) : Until Inkey() <> ""
|
||||
CloseConsole()
|
||||
EndIf
|
||||
2
Task/Write-entire-file/Python/write-entire-file-1.py
Normal file
2
Task/Write-entire-file/Python/write-entire-file-1.py
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
with open(filename, 'w') as f:
|
||||
f.write(data)
|
||||
4
Task/Write-entire-file/Python/write-entire-file-2.py
Normal file
4
Task/Write-entire-file/Python/write-entire-file-2.py
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
from pathlib import Path
|
||||
|
||||
Path(filename).write_text(any_string)
|
||||
Path(filename).write_bytes(any_binary_data)
|
||||
4
Task/Write-entire-file/QBasic/write-entire-file.basic
Normal file
4
Task/Write-entire-file/QBasic/write-entire-file.basic
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
f = FREEFILE
|
||||
OPEN "output.txt" FOR OUTPUT AS #f
|
||||
PRINT #f, "This string is to be written to the file"
|
||||
CLOSE #
|
||||
8
Task/Write-entire-file/RATFOR/write-entire-file.ratfor
Normal file
8
Task/Write-entire-file/RATFOR/write-entire-file.ratfor
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
# Program to overwrite an existing file
|
||||
|
||||
open(11,FILE="file.txt")
|
||||
101 format(A)
|
||||
write(11,101) "Hello World"
|
||||
close(11)
|
||||
|
||||
end
|
||||
8
Task/Write-entire-file/REXX/write-entire-file-1.rexx
Normal file
8
Task/Write-entire-file/REXX/write-entire-file-1.rexx
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
/*REXX*/
|
||||
|
||||
of='file.txt'
|
||||
'erase' of
|
||||
s=copies('1234567890',10000)
|
||||
Call charout of,s
|
||||
Call lineout of
|
||||
Say chars(of) length(s)
|
||||
8
Task/Write-entire-file/REXX/write-entire-file-2.rexx
Normal file
8
Task/Write-entire-file/REXX/write-entire-file-2.rexx
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
/*REXX program writes an entire file with a single write (a long text record). */
|
||||
oFID= 'OUTPUT.DAT' /*name of the output file to be used. */
|
||||
/* [↓] 50 bytes, including the fences.*/
|
||||
$ = '<<<This is the text that is written to a file. >>>'
|
||||
/* [↓] COPIES creates a 50k byte str.*/
|
||||
call charout oFID, copies($,1000), 1 /*write the longish text to the file. */
|
||||
/* [↑] the "1" writes text ──► rec #1*/
|
||||
/*stick a fork in it, we're all done. */
|
||||
3
Task/Write-entire-file/Racket/write-entire-file.rkt
Normal file
3
Task/Write-entire-file/Racket/write-entire-file.rkt
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
#lang racket/base
|
||||
(with-output-to-file "/tmp/out-file.txt" #:exists 'replace
|
||||
(lambda () (display "characters")))
|
||||
1
Task/Write-entire-file/Raku/write-entire-file-1.raku
Normal file
1
Task/Write-entire-file/Raku/write-entire-file-1.raku
Normal file
|
|
@ -0,0 +1 @@
|
|||
spurt 'path/to/file', $file-data;
|
||||
1
Task/Write-entire-file/Raku/write-entire-file-2.raku
Normal file
1
Task/Write-entire-file/Raku/write-entire-file-2.raku
Normal file
|
|
@ -0,0 +1 @@
|
|||
'path/to/file'.IO.spurt: $file-data;
|
||||
1
Task/Write-entire-file/Ring/write-entire-file.ring
Normal file
1
Task/Write-entire-file/Ring/write-entire-file.ring
Normal file
|
|
@ -0,0 +1 @@
|
|||
write("myfile.txt","Hello, World!")
|
||||
1
Task/Write-entire-file/Ruby/write-entire-file.rb
Normal file
1
Task/Write-entire-file/Ruby/write-entire-file.rb
Normal file
|
|
@ -0,0 +1 @@
|
|||
open(fname, 'w'){|f| f.write(str) }
|
||||
3
Task/Write-entire-file/Run-BASIC/write-entire-file.basic
Normal file
3
Task/Write-entire-file/Run-BASIC/write-entire-file.basic
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
open "output.txt" for output as #1
|
||||
print #1, "This string is to be written to the file"
|
||||
close #1
|
||||
9
Task/Write-entire-file/Rust/write-entire-file.rust
Normal file
9
Task/Write-entire-file/Rust/write-entire-file.rust
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
use std::fs::File;
|
||||
use std::io::Write;
|
||||
|
||||
fn main() -> std::io::Result<()> {
|
||||
let data = "Sample text.";
|
||||
let mut file = File::create("filename.txt")?;
|
||||
write!(file, "{}", data)?;
|
||||
Ok(())
|
||||
}
|
||||
1
Task/Write-entire-file/SPL/write-entire-file.spl
Normal file
1
Task/Write-entire-file/SPL/write-entire-file.spl
Normal file
|
|
@ -0,0 +1 @@
|
|||
#.writetext("file.txt","This is the string")
|
||||
10
Task/Write-entire-file/Scala/write-entire-file.scala
Normal file
10
Task/Write-entire-file/Scala/write-entire-file.scala
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
import java.io.{File, PrintWriter}
|
||||
|
||||
object Main extends App {
|
||||
val pw = new PrintWriter(new File("Flumberboozle.txt"),"UTF8"){
|
||||
print("My zirconconductor short-circuited and I'm having trouble fixing this issue.\nI researched" +
|
||||
" online and they said that I need to connect my flumberboozle to the XKG virtual port, but I was" +
|
||||
" wondering if I also needed a galvanized tungsten retrothruster array? Maybe it'd help the" +
|
||||
" frictional radial anti-stabilizer vectronize from the flumberboozle to the XKG virtual port?")
|
||||
close()}
|
||||
}
|
||||
|
|
@ -0,0 +1 @@
|
|||
put "New String" into file "~/Desktop/myFile.txt"
|
||||
3
Task/Write-entire-file/Sidef/write-entire-file-1.sidef
Normal file
3
Task/Write-entire-file/Sidef/write-entire-file-1.sidef
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
var file = File(__FILE__)
|
||||
file.open_w(\var fh, \var err) || die "Can't open #{file}: #{err}"
|
||||
fh.print("Hello world!") || die "Can't write to #{file}: #{$!}"
|
||||
1
Task/Write-entire-file/Sidef/write-entire-file-2.sidef
Normal file
1
Task/Write-entire-file/Sidef/write-entire-file-2.sidef
Normal file
|
|
@ -0,0 +1 @@
|
|||
File(__FILE__).open_w.print("Hello world!")
|
||||
1
Task/Write-entire-file/Smalltalk/write-entire-file.st
Normal file
1
Task/Write-entire-file/Smalltalk/write-entire-file.st
Normal file
|
|
@ -0,0 +1 @@
|
|||
'file.txt' asFilename contents:'Hello World'
|
||||
3
Task/Write-entire-file/Standard-ML/write-entire-file.ml
Normal file
3
Task/Write-entire-file/Standard-ML/write-entire-file.ml
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
fun writeFile (path, str) =
|
||||
(fn strm =>
|
||||
TextIO.output (strm, str) before TextIO.closeOut strm) (TextIO.openOut path)
|
||||
8
Task/Write-entire-file/TUSCRIPT/write-entire-file.tu
Normal file
8
Task/Write-entire-file/TUSCRIPT/write-entire-file.tu
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
$$ MODE TUSCRIPT
|
||||
content="new text that will overwrite content of myfile"
|
||||
LOOP
|
||||
path2file=FULLNAME (TUSTEP,"myfile",-std-)
|
||||
status=WRITE (path2file,content)
|
||||
IF (status=="OK") EXIT
|
||||
IF (status=="CREATE") ERROR/STOP CREATE ("myfile",seq-o,-std-)
|
||||
ENDLOOP
|
||||
8
Task/Write-entire-file/Tcl/write-entire-file.tcl
Normal file
8
Task/Write-entire-file/Tcl/write-entire-file.tcl
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
proc writefile {filename data} {
|
||||
set fd [open $filename w] ;# truncate if exists, else create
|
||||
try {
|
||||
puts -nonewline $fd $data
|
||||
} finally {
|
||||
close $fd
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,4 @@
|
|||
OPEN #1: NAME "output.txt", CREATE NEWOLD
|
||||
PRINT #1: "This string is to be written to the file"
|
||||
CLOSE #1
|
||||
END
|
||||
3
Task/Write-entire-file/V-(Vlang)/write-entire-file.v
Normal file
3
Task/Write-entire-file/V-(Vlang)/write-entire-file.v
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
import os
|
||||
|
||||
os.write_file('./hello_text.txt', 'Hello there!') or {println('Error: failed to write.') exit(1)}
|
||||
15
Task/Write-entire-file/VBA/write-entire-file.vba
Normal file
15
Task/Write-entire-file/VBA/write-entire-file.vba
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
Option Explicit
|
||||
|
||||
Const strName As String = "MyFileText.txt"
|
||||
Const Text As String = "(Over)write a file so that it contains a string. " & vbCrLf & _
|
||||
"The reverse of Read entire file—for when you want to update or " & vbCrLf & _
|
||||
"create a file which you would read in its entirety all at once."
|
||||
|
||||
Sub Main()
|
||||
Dim Nb As Integer
|
||||
|
||||
Nb = FreeFile
|
||||
Open "C:\Users\" & Environ("username") & "\Desktop\" & strName For Output As #Nb
|
||||
Print #1, Text
|
||||
Close #Nb
|
||||
End Sub
|
||||
12
Task/Write-entire-file/VBScript/write-entire-file.vb
Normal file
12
Task/Write-entire-file/VBScript/write-entire-file.vb
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
Set objFSO = CreateObject("Scripting.FileSystemObject")
|
||||
|
||||
SourceFile = objFSO.GetParentFolderName(WScript.ScriptFullName) & "\out.txt"
|
||||
Content = "(Over)write a file so that it contains a string." & vbCrLf &_
|
||||
"The reverse of Read entire file—for when you want to update or create a file which you would read in its entirety all at once."
|
||||
|
||||
With objFSO.OpenTextFile(SourceFile,2,True,0)
|
||||
.Write Content
|
||||
.Close
|
||||
End With
|
||||
|
||||
Set objFSO = Nothing
|
||||
|
|
@ -0,0 +1,7 @@
|
|||
Module Module1
|
||||
|
||||
Sub Main()
|
||||
My.Computer.FileSystem.WriteAllText("new.txt", "This is a string", False)
|
||||
End Sub
|
||||
|
||||
End Module
|
||||
17
Task/Write-entire-file/Wren/write-entire-file.wren
Normal file
17
Task/Write-entire-file/Wren/write-entire-file.wren
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
import "io" for File
|
||||
|
||||
// create a text file
|
||||
File.create("hello.txt") { |file|
|
||||
file.writeBytes("hello")
|
||||
}
|
||||
|
||||
// check it worked
|
||||
System.print(File.read("hello.txt"))
|
||||
|
||||
// overwrite it by 'creating' the file again
|
||||
File.create("hello.txt") {|file|
|
||||
file.writeBytes("goodbye")
|
||||
}
|
||||
|
||||
// check it worked
|
||||
System.print(File.read("hello.txt"))
|
||||
3
Task/Write-entire-file/XLISP/write-entire-file.l
Normal file
3
Task/Write-entire-file/XLISP/write-entire-file.l
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
(define n (open-output-file "example.txt"))
|
||||
(write "(Over)write a file so that it contains a string." n)
|
||||
(close-output-port n)
|
||||
3
Task/Write-entire-file/XPL0/write-entire-file.xpl0
Normal file
3
Task/Write-entire-file/XPL0/write-entire-file.xpl0
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
[FSet(FOpen("output.txt", 1), ^o);
|
||||
Text(3, "This is a string.");
|
||||
]
|
||||
3
Task/Write-entire-file/Yabasic/write-entire-file.basic
Normal file
3
Task/Write-entire-file/Yabasic/write-entire-file.basic
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
open "output.txt" for writing as #1
|
||||
print #1 "This is a string"
|
||||
close #1
|
||||
6
Task/Write-entire-file/Zkl/write-entire-file.zkl
Normal file
6
Task/Write-entire-file/Zkl/write-entire-file.zkl
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
// write returns bytes written, GC will close the file (eventually)
|
||||
File("foo","wb").write("this is a test",1,2,3); //-->17
|
||||
|
||||
f:=File("bar",wb");
|
||||
data.pump(f,g); // use g to process data as it is written to file
|
||||
f.close(); // don't wait for GC
|
||||
Loading…
Add table
Add a link
Reference in a new issue