Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
3
Task/Read-entire-file/00-META.yaml
Normal file
3
Task/Read-entire-file/00-META.yaml
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
---
|
||||
from: http://rosettacode.org/wiki/Read_entire_file
|
||||
note: File handling
|
||||
11
Task/Read-entire-file/00-TASK.txt
Normal file
11
Task/Read-entire-file/00-TASK.txt
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
;Task:
|
||||
Load the entire contents of some text file as a single string variable.
|
||||
|
||||
If applicable, discuss: encoding selection, the possibility of memory-mapping.
|
||||
|
||||
Of course, in practice one should avoid reading an entire file at once
|
||||
if the file is large and the task can be accomplished incrementally instead
|
||||
(in which case check [[File IO]]);
|
||||
this is for those cases where having the entire file is actually what is wanted.
|
||||
<br><br>
|
||||
|
||||
1
Task/Read-entire-file/11l/read-entire-file.11l
Normal file
1
Task/Read-entire-file/11l/read-entire-file.11l
Normal file
|
|
@ -0,0 +1 @@
|
|||
File(filename).read()
|
||||
1
Task/Read-entire-file/8th/read-entire-file.8th
Normal file
1
Task/Read-entire-file/8th/read-entire-file.8th
Normal file
|
|
@ -0,0 +1 @@
|
|||
"somefile.txt" f:slurp >s
|
||||
7
Task/Read-entire-file/ALGOL-68/read-entire-file-1.alg
Normal file
7
Task/Read-entire-file/ALGOL-68/read-entire-file-1.alg
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
MODE BOOK = FLEX[0]FLEX[0]FLEX[0]CHAR; ¢ pages of lines of characters ¢
|
||||
BOOK book;
|
||||
|
||||
FILE book file;
|
||||
INT errno = open(book file, "book.txt", stand in channel);
|
||||
|
||||
get(book file, book)
|
||||
2
Task/Read-entire-file/ALGOL-68/read-entire-file-2.alg
Normal file
2
Task/Read-entire-file/ALGOL-68/read-entire-file-2.alg
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
FILE cached book file;
|
||||
associate(cached book file, book)
|
||||
1
Task/Read-entire-file/ATS/read-entire-file.ats
Normal file
1
Task/Read-entire-file/ATS/read-entire-file.ats
Normal file
|
|
@ -0,0 +1 @@
|
|||
val s = fileref_get_file_string (stdin_ref)
|
||||
13
Task/Read-entire-file/AWK/read-entire-file-1.awk
Normal file
13
Task/Read-entire-file/AWK/read-entire-file-1.awk
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
#!/usr/bin/awk -f
|
||||
BEGIN {
|
||||
## empty record separate,
|
||||
RS="";
|
||||
## read line (i.e. whole file) into $0
|
||||
getline;
|
||||
## print line number and content of line
|
||||
print "=== line "NR,":",$0;
|
||||
}
|
||||
{
|
||||
## no further line is read printed
|
||||
print "=== line "NR,":",$0;
|
||||
}
|
||||
10
Task/Read-entire-file/AWK/read-entire-file-2.awk
Normal file
10
Task/Read-entire-file/AWK/read-entire-file-2.awk
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
#!/usr/bin/awk -f
|
||||
|
||||
@include "readfile"
|
||||
|
||||
BEGIN {
|
||||
|
||||
str = readfile("file.txt")
|
||||
print str
|
||||
|
||||
}
|
||||
6
Task/Read-entire-file/Action-/read-entire-file.action
Normal file
6
Task/Read-entire-file/Action-/read-entire-file.action
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
proc MAIN()
|
||||
char array STRING
|
||||
open (1,"D:FILE.TXT",4,0)
|
||||
inputsd(1,STRING)
|
||||
close(1)
|
||||
return
|
||||
23
Task/Read-entire-file/Ada/read-entire-file-1.ada
Normal file
23
Task/Read-entire-file/Ada/read-entire-file-1.ada
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
with Ada.Directories,
|
||||
Ada.Direct_IO,
|
||||
Ada.Text_IO;
|
||||
|
||||
procedure Whole_File is
|
||||
|
||||
File_Name : String := "whole_file.adb";
|
||||
File_Size : Natural := Natural (Ada.Directories.Size (File_Name));
|
||||
|
||||
subtype File_String is String (1 .. File_Size);
|
||||
package File_String_IO is new Ada.Direct_IO (File_String);
|
||||
|
||||
File : File_String_IO.File_Type;
|
||||
Contents : File_String;
|
||||
|
||||
begin
|
||||
File_String_IO.Open (File, Mode => File_String_IO.In_File,
|
||||
Name => File_Name);
|
||||
File_String_IO.Read (File, Item => Contents);
|
||||
File_String_IO.Close (File);
|
||||
|
||||
Ada.Text_IO.Put (Contents);
|
||||
end Whole_File;
|
||||
35
Task/Read-entire-file/Ada/read-entire-file-2.ada
Normal file
35
Task/Read-entire-file/Ada/read-entire-file-2.ada
Normal file
|
|
@ -0,0 +1,35 @@
|
|||
with Ada.Text_IO,
|
||||
POSIX.IO,
|
||||
POSIX.Memory_Mapping,
|
||||
System.Storage_Elements;
|
||||
|
||||
procedure Read_Entire_File is
|
||||
|
||||
use POSIX, POSIX.IO, POSIX.Memory_Mapping;
|
||||
use System.Storage_Elements;
|
||||
|
||||
Text_File : File_Descriptor;
|
||||
Text_Size : System.Storage_Elements.Storage_Offset;
|
||||
Text_Address : System.Address;
|
||||
|
||||
begin
|
||||
Text_File := Open (Name => "read_entire_file.adb",
|
||||
Mode => Read_Only);
|
||||
Text_Size := Storage_Offset (File_Size (Text_File));
|
||||
Text_Address := Map_Memory (Length => Text_Size,
|
||||
Protection => Allow_Read,
|
||||
Mapping => Map_Shared,
|
||||
File => Text_File,
|
||||
Offset => 0);
|
||||
|
||||
declare
|
||||
Text : String (1 .. Natural (Text_Size));
|
||||
for Text'Address use Text_Address;
|
||||
begin
|
||||
Ada.Text_IO.Put (Text);
|
||||
end;
|
||||
|
||||
Unmap_Memory (First => Text_Address,
|
||||
Length => Text_Size);
|
||||
Close (File => Text_File);
|
||||
end Read_Entire_File;
|
||||
|
|
@ -0,0 +1,7 @@
|
|||
#include <hopper.h>
|
||||
|
||||
main:
|
||||
s=""
|
||||
load str ("archivo.txt") (s)
|
||||
println ( "File loaded:\n",s )
|
||||
exit(0)
|
||||
|
|
@ -0,0 +1,9 @@
|
|||
set pathToTextFile to ((path to desktop folder as string) & "testfile.txt")
|
||||
|
||||
-- short way: open, read and close in one step
|
||||
set fileContent to read file pathToTextFile
|
||||
|
||||
-- long way: open a file reference, read content and close access
|
||||
set fileRef to open for access pathToTextFile
|
||||
set fileContent to read fileRef
|
||||
close access fileRef
|
||||
15
Task/Read-entire-file/Applesoft-BASIC/read-entire-file.basic
Normal file
15
Task/Read-entire-file/Applesoft-BASIC/read-entire-file.basic
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
100 D$ = CHR$ (4)
|
||||
110 F$ = "INPUT.TXT"
|
||||
120 PRINT D$"VERIFY"F$
|
||||
130 PRINT D$"OPEN"F$
|
||||
140 PRINT D$"READ"F$
|
||||
150 ONERR GOTO 210
|
||||
160 GET C$
|
||||
170 POKE 216,0
|
||||
180 S$ = S$ + C$
|
||||
190 PRINT
|
||||
200 GOTO 140
|
||||
210 POKE 216,0
|
||||
220 EOF = PEEK (222) = 5
|
||||
230 IF NOT EOF THEN RESUME
|
||||
240 PRINT D$"CLOSE"F$
|
||||
1
Task/Read-entire-file/Arturo/read-entire-file.arturo
Normal file
1
Task/Read-entire-file/Arturo/read-entire-file.arturo
Normal file
|
|
@ -0,0 +1 @@
|
|||
contents: read "input.txt"
|
||||
1
Task/Read-entire-file/AutoHotkey/read-entire-file.ahk
Normal file
1
Task/Read-entire-file/AutoHotkey/read-entire-file.ahk
Normal file
|
|
@ -0,0 +1 @@
|
|||
fileread, varname, C:\filename.txt ; adding "MsgBox %varname%" (no quotes) to the next line will display the file contents.
|
||||
3
Task/Read-entire-file/AutoIt/read-entire-file.autoit
Normal file
3
Task/Read-entire-file/AutoIt/read-entire-file.autoit
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
$fileOpen = FileOpen("file.txt")
|
||||
$fileRead = FileRead($fileOpen)
|
||||
FileClose($fileOpen)
|
||||
5
Task/Read-entire-file/BASIC/read-entire-file.basic
Normal file
5
Task/Read-entire-file/BASIC/read-entire-file.basic
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
DIM f AS STRING
|
||||
OPEN "file.txt" FOR BINARY AS 1
|
||||
f = SPACE$(LOF(1))
|
||||
GET #1, 1, f
|
||||
CLOSE 1
|
||||
7
Task/Read-entire-file/BASIC256/read-entire-file.basic
Normal file
7
Task/Read-entire-file/BASIC256/read-entire-file.basic
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
f = freefile
|
||||
open f, "input.txt"
|
||||
while not eof(f)
|
||||
linea$ = readline(f)
|
||||
print linea$
|
||||
end while
|
||||
close f
|
||||
6
Task/Read-entire-file/BBC-BASIC/read-entire-file-1.basic
Normal file
6
Task/Read-entire-file/BBC-BASIC/read-entire-file-1.basic
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
file% = OPENIN("input.txt")
|
||||
strvar$ = ""
|
||||
WHILE NOT EOF#file%
|
||||
strvar$ += CHR$(BGET#file%)
|
||||
ENDWHILE
|
||||
CLOSE #file%
|
||||
4
Task/Read-entire-file/BBC-BASIC/read-entire-file-2.basic
Normal file
4
Task/Read-entire-file/BBC-BASIC/read-entire-file-2.basic
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
file% = OPENIN("input.txt")
|
||||
strvar$ = STRING$(EXT#file%, " ")
|
||||
SYS "ReadFile", @hfile%(file%), !^strvar$, EXT#file%, ^temp%, 0
|
||||
CLOSE #file%
|
||||
6
Task/Read-entire-file/BQN/read-entire-file.bqn
Normal file
6
Task/Read-entire-file/BQN/read-entire-file.bqn
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
•file.Chars "file"
|
||||
•file.Bytes "file"
|
||||
|
||||
# Shorthands:
|
||||
•FChars "file"
|
||||
•FBytes "file"
|
||||
1
Task/Read-entire-file/BaCon/read-entire-file-1.bacon
Normal file
1
Task/Read-entire-file/BaCon/read-entire-file-1.bacon
Normal file
|
|
@ -0,0 +1 @@
|
|||
content$ = LOAD$(filename$)
|
||||
3
Task/Read-entire-file/BaCon/read-entire-file-2.bacon
Normal file
3
Task/Read-entire-file/BaCon/read-entire-file-2.bacon
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
binary = BLOAD("somefile.bin")
|
||||
PRINT "First two bytes are: ", PEEK(binary), " ", PEEK(binary+1)
|
||||
FREE binary
|
||||
47
Task/Read-entire-file/Blue/read-entire-file.blue
Normal file
47
Task/Read-entire-file/Blue/read-entire-file.blue
Normal file
|
|
@ -0,0 +1,47 @@
|
|||
global _start
|
||||
|
||||
: syscall ( num:eax -- result:eax ) syscall ;
|
||||
|
||||
: exit ( status:edi -- noret ) 60 syscall ;
|
||||
: bye ( -- noret ) 0 exit ;
|
||||
: die ( err:eax -- noret ) neg exit ;
|
||||
|
||||
: unwrap ( result:eax -- value:eax ) dup 0 cmp ' die xl ;
|
||||
: ordie ( result -- ) unwrap drop ;
|
||||
|
||||
: open ( pathname:edi flags:esi -- fd:eax ) 2 syscall unwrap ;
|
||||
: close ( fd:edi -- ) 3 syscall ordie ;
|
||||
|
||||
48 resb stat_buf
|
||||
8 resb file-size
|
||||
88 resb padding
|
||||
|
||||
: fstat ( fd:edi buf:esi -- ) 5 syscall ordie ;
|
||||
|
||||
1 const prot_read
|
||||
2 const map_private
|
||||
|
||||
: mmap ( fd:r8d len:esi addr:edi off:r9d prot:edx flags:r10d -- buf:eax ) 9 syscall unwrap ;
|
||||
: munmap ( addr:edi len:esi -- ) 11 syscall ordie ;
|
||||
|
||||
1 resd fd
|
||||
0 const read-only
|
||||
|
||||
: open-file ( pathname:edi -- ) read-only open fd ! ;
|
||||
: read-file-size ( -- ) fd @ stat_buf fstat ;
|
||||
: map-file ( fd len -- buf ) 0 0 prot_read map_private mmap ;
|
||||
: map-file ( -- buf ) fd @ file-size @ map-file ;
|
||||
: unmap-file ( buf -- ) file-size @ munmap ;
|
||||
: close-file ( -- ) fd @ close ;
|
||||
|
||||
: open-this-file ( -- ) s" read_entire_file.blue" drop open-file ;
|
||||
|
||||
: _start ( -- noret )
|
||||
open-this-file
|
||||
read-file-size
|
||||
map-file
|
||||
\ do something ...
|
||||
unmap-file
|
||||
close-file
|
||||
bye
|
||||
;
|
||||
4
Task/Read-entire-file/Brainf---/read-entire-file.bf
Normal file
4
Task/Read-entire-file/Brainf---/read-entire-file.bf
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
> Keep cell 0 at 0 as a sentinel value
|
||||
,[>,] Read into successive cells until EOF
|
||||
<[<] Go all the way back to the beginning
|
||||
>[.>] Print successive cells while nonzero
|
||||
3
Task/Read-entire-file/Brat/read-entire-file.brat
Normal file
3
Task/Read-entire-file/Brat/read-entire-file.brat
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
include :file
|
||||
|
||||
file.read file_name
|
||||
23
Task/Read-entire-file/C++/read-entire-file.cpp
Normal file
23
Task/Read-entire-file/C++/read-entire-file.cpp
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
#include <iostream>
|
||||
#include <fstream>
|
||||
#include <string>
|
||||
#include <iterator>
|
||||
|
||||
int main( )
|
||||
{
|
||||
if (std::ifstream infile("sample.txt"))
|
||||
{
|
||||
// construct string from iterator range
|
||||
std::string fileData(std::istreambuf_iterator<char>(infile), std::istreambuf_iterator<char>());
|
||||
|
||||
cout << "File has " << fileData.size() << "chars\n";
|
||||
|
||||
// don't need to manually close the ifstream; it will release the file when it goes out of scope
|
||||
return 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
std::cout << "file not found!\n";
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
10
Task/Read-entire-file/C-sharp/read-entire-file.cs
Normal file
10
Task/Read-entire-file/C-sharp/read-entire-file.cs
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
using System.IO;
|
||||
|
||||
class Program
|
||||
{
|
||||
static void Main(string[] args)
|
||||
{
|
||||
var fileContents = File.ReadAllText("c:\\autoexec.bat");
|
||||
// Can optionally take a second parameter to specify the encoding, e.g. File.ReadAllText("c:\\autoexec.bat", Encoding.UTF8)
|
||||
}
|
||||
}
|
||||
28
Task/Read-entire-file/C/read-entire-file-1.c
Normal file
28
Task/Read-entire-file/C/read-entire-file-1.c
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
int main()
|
||||
{
|
||||
char *buffer;
|
||||
FILE *fh = fopen("readentirefile.c", "rb");
|
||||
if ( fh != NULL )
|
||||
{
|
||||
fseek(fh, 0L, SEEK_END);
|
||||
long s = ftell(fh);
|
||||
rewind(fh);
|
||||
buffer = malloc(s);
|
||||
if ( buffer != NULL )
|
||||
{
|
||||
fread(buffer, s, 1, fh);
|
||||
// we can now close the file
|
||||
fclose(fh); fh = NULL;
|
||||
|
||||
// do something, e.g.
|
||||
fwrite(buffer, s, 1, stdout);
|
||||
|
||||
free(buffer);
|
||||
}
|
||||
if (fh != NULL) fclose(fh);
|
||||
}
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
29
Task/Read-entire-file/C/read-entire-file-2.c
Normal file
29
Task/Read-entire-file/C/read-entire-file-2.c
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <sys/mman.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <unistd.h>
|
||||
#include <fcntl.h>
|
||||
|
||||
int main()
|
||||
{
|
||||
char *buffer;
|
||||
struct stat s;
|
||||
|
||||
int fd = open("readentirefile_mm.c", O_RDONLY);
|
||||
if (fd < 0 ) return EXIT_FAILURE;
|
||||
fstat(fd, &s);
|
||||
/* PROT_READ disallows writing to buffer: will segv */
|
||||
buffer = mmap(0, s.st_size, PROT_READ, MAP_PRIVATE, fd, 0);
|
||||
|
||||
if ( buffer != (void*)-1 )
|
||||
{
|
||||
/* do something */
|
||||
fwrite(buffer, s.st_size, 1, stdout);
|
||||
munmap(buffer, s.st_size);
|
||||
}
|
||||
|
||||
close(fd);
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
19
Task/Read-entire-file/C/read-entire-file-3.c
Normal file
19
Task/Read-entire-file/C/read-entire-file-3.c
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
#include <windows.h>
|
||||
#include <stdio.h>
|
||||
|
||||
int main() {
|
||||
HANDLE hFile, hMap;
|
||||
DWORD filesize;
|
||||
char *p;
|
||||
|
||||
hFile = CreateFile("mmap_win.c", GENERIC_READ, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
|
||||
filesize = GetFileSize(hFile, NULL);
|
||||
hMap = CreateFileMapping(hFile, NULL, PAGE_READONLY, 0, 0, NULL);
|
||||
p = MapViewOfFile(hMap, FILE_MAP_READ, 0, 0, 0);
|
||||
|
||||
fwrite(p, filesize, 1, stdout);
|
||||
|
||||
CloseHandle(hMap);
|
||||
CloseHandle(hFile);
|
||||
return 0;
|
||||
}
|
||||
1
Task/Read-entire-file/CMake/read-entire-file-1.cmake
Normal file
1
Task/Read-entire-file/CMake/read-entire-file-1.cmake
Normal file
|
|
@ -0,0 +1 @@
|
|||
file(READ /etc/passwd string)
|
||||
1
Task/Read-entire-file/CMake/read-entire-file-2.cmake
Normal file
1
Task/Read-entire-file/CMake/read-entire-file-2.cmake
Normal file
|
|
@ -0,0 +1 @@
|
|||
file(READ /etc/pwd.db string HEX)
|
||||
2
Task/Read-entire-file/Clojure/read-entire-file.clj
Normal file
2
Task/Read-entire-file/Clojure/read-entire-file.clj
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
(slurp "myfile.txt")
|
||||
(slurp "my-utf8-file.txt" "UTF-8")
|
||||
14
Task/Read-entire-file/Commodore-BASIC/read-entire-file.basic
Normal file
14
Task/Read-entire-file/Commodore-BASIC/read-entire-file.basic
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
10 rem load the entire contents of some text file as a single string variable.
|
||||
20 rem should avoid reading an entire file at once if the file is large
|
||||
30 rem ================================
|
||||
40 print chr$(14) : rem switch to upper+lowercase character set
|
||||
50 open 4,8,4,"data.txt,seq,read"
|
||||
60 n=0
|
||||
70 for i=0 to 1
|
||||
80 get#4,x$
|
||||
90 i=st and 64 : rem check for 'end-of-file'
|
||||
100 if i=0 then a$=a$+x$ : n=n+1
|
||||
110 if n=255 then i=1 : rem max string length is 255 only
|
||||
120 next
|
||||
130 close 4
|
||||
140 end
|
||||
5
Task/Read-entire-file/Common-Lisp/read-entire-file.lisp
Normal file
5
Task/Read-entire-file/Common-Lisp/read-entire-file.lisp
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
(defun file-string (path)
|
||||
(with-open-file (stream path)
|
||||
(let ((data (make-string (file-length stream))))
|
||||
(read-sequence data stream)
|
||||
data)))
|
||||
2
Task/Read-entire-file/Crystal/read-entire-file-1.crystal
Normal file
2
Task/Read-entire-file/Crystal/read-entire-file-1.crystal
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
content = File.read("input.txt")
|
||||
puts content
|
||||
1
Task/Read-entire-file/Crystal/read-entire-file-2.crystal
Normal file
1
Task/Read-entire-file/Crystal/read-entire-file-2.crystal
Normal file
|
|
@ -0,0 +1 @@
|
|||
content = File.read("input.txt", "UTF-16")
|
||||
1
Task/Read-entire-file/Crystal/read-entire-file-3.crystal
Normal file
1
Task/Read-entire-file/Crystal/read-entire-file-3.crystal
Normal file
|
|
@ -0,0 +1 @@
|
|||
content = File.read("input.txt", encoding: "UTF-16")
|
||||
3
Task/Read-entire-file/Crystal/read-entire-file-4.crystal
Normal file
3
Task/Read-entire-file/Crystal/read-entire-file-4.crystal
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
content = File.open("input.txt") do |file|
|
||||
file.gets_to_end
|
||||
end
|
||||
3
Task/Read-entire-file/Crystal/read-entire-file-5.crystal
Normal file
3
Task/Read-entire-file/Crystal/read-entire-file-5.crystal
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
file = File.new("input.txt")
|
||||
content = file.gets_to_end
|
||||
file.close
|
||||
9
Task/Read-entire-file/D/read-entire-file.d
Normal file
9
Task/Read-entire-file/D/read-entire-file.d
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
import std.file: read, readText;
|
||||
|
||||
void main() {
|
||||
// To read a whole file into a dynamic array of unsigned bytes:
|
||||
auto data = cast(ubyte[])read("unixdict.txt");
|
||||
|
||||
// To read a whole file into a validated UTF-8 string:
|
||||
string txt = readText("unixdict.txt");
|
||||
}
|
||||
22
Task/Read-entire-file/Delphi/read-entire-file-1.delphi
Normal file
22
Task/Read-entire-file/Delphi/read-entire-file-1.delphi
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
program ReadAll;
|
||||
|
||||
{$APPTYPE CONSOLE}
|
||||
|
||||
uses Classes;
|
||||
|
||||
var
|
||||
i: Integer;
|
||||
lList: TStringList;
|
||||
begin
|
||||
lList := TStringList.Create;
|
||||
try
|
||||
lList.LoadFromFile('c:\input.txt');
|
||||
// Write everything at once
|
||||
Writeln(lList.Text);
|
||||
// Write one line at a time
|
||||
for i := 0 to lList.Count - 1 do
|
||||
Writeln(lList[i]);
|
||||
finally
|
||||
lList.Free;
|
||||
end;
|
||||
end.
|
||||
14
Task/Read-entire-file/Delphi/read-entire-file-2.delphi
Normal file
14
Task/Read-entire-file/Delphi/read-entire-file-2.delphi
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
program ReadAll;
|
||||
|
||||
{$APPTYPE CONSOLE}
|
||||
|
||||
uses
|
||||
SysUtils, IOUtils;
|
||||
|
||||
begin
|
||||
// with default encoding:
|
||||
Writeln(TFile.ReadAllText('C:\autoexec.bat'));
|
||||
// with encoding specified:
|
||||
Writeln(TFile.ReadAllText('C:\autoexec.bat', TEncoding.ASCII));
|
||||
Readln;
|
||||
end.
|
||||
1
Task/Read-entire-file/E/read-entire-file.e
Normal file
1
Task/Read-entire-file/E/read-entire-file.e
Normal file
|
|
@ -0,0 +1 @@
|
|||
<file:foo.txt>.getText()
|
||||
3
Task/Read-entire-file/Ecstasy/read-entire-file-1.ecstasy
Normal file
3
Task/Read-entire-file/Ecstasy/read-entire-file-1.ecstasy
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
static Byte[] contentsOf(File file) {
|
||||
return file.contents;
|
||||
}
|
||||
2
Task/Read-entire-file/Ecstasy/read-entire-file-2.ecstasy
Normal file
2
Task/Read-entire-file/Ecstasy/read-entire-file-2.ecstasy
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
Byte[] bytes = #./checkmark.ico;
|
||||
String html = $/docs/website/index.htm;
|
||||
5
Task/Read-entire-file/Ecstasy/read-entire-file-3.ecstasy
Normal file
5
Task/Read-entire-file/Ecstasy/read-entire-file-3.ecstasy
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
File iconFile = ./checkmark.ico;
|
||||
File htmlFile = /docs/website/index.htm;
|
||||
|
||||
Byte[] bytes = iconFile.contents;
|
||||
String html = htmlFile.contents.unpackUtf8();
|
||||
23
Task/Read-entire-file/Elixir/read-entire-file.elixir
Normal file
23
Task/Read-entire-file/Elixir/read-entire-file.elixir
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
defmodule FileReader do
|
||||
# Read in the file
|
||||
def read(path) do
|
||||
case File.read(path) do
|
||||
{:ok, body} ->
|
||||
IO.inspect body
|
||||
{:error,reason} ->
|
||||
:file.format_error(reason)
|
||||
end
|
||||
end
|
||||
|
||||
# Open the file path, then read in the file
|
||||
def bit_read(path) do
|
||||
case File.open(path) do
|
||||
{:ok, file} ->
|
||||
# :all can be replaced with :line, or with a positive integer to specify the number of characters to read.
|
||||
IO.read(file,:all)
|
||||
|> IO.inspect
|
||||
{:error,reason} ->
|
||||
:file.format_error(reason)
|
||||
end
|
||||
end
|
||||
end
|
||||
3
Task/Read-entire-file/Emacs-Lisp/read-entire-file.l
Normal file
3
Task/Read-entire-file/Emacs-Lisp/read-entire-file.l
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
(setq my-variable (with-temp-buffer
|
||||
(insert-file-contents "foo.txt")
|
||||
(buffer-string)))
|
||||
1
Task/Read-entire-file/Erlang/read-entire-file.erl
Normal file
1
Task/Read-entire-file/Erlang/read-entire-file.erl
Normal file
|
|
@ -0,0 +1 @@
|
|||
{ok, B} = file:read_file("myfile.txt").
|
||||
16
Task/Read-entire-file/Euphoria/read-entire-file.euphoria
Normal file
16
Task/Read-entire-file/Euphoria/read-entire-file.euphoria
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
function load_file(sequence filename)
|
||||
integer fn,c
|
||||
sequence data
|
||||
fn = open(filename,"r") -- "r" for text files, "rb" for binary files
|
||||
if (fn = -1) then return {} end if -- failed to open the file
|
||||
|
||||
data = {} -- init to empty sequence
|
||||
c = getc(fn) -- prime the char buffer
|
||||
while (c != -1) do -- while not EOF
|
||||
data &= c -- append each character
|
||||
c = getc(fn) -- next char
|
||||
end while
|
||||
|
||||
close(fn)
|
||||
return data
|
||||
end function
|
||||
4
Task/Read-entire-file/F-Sharp/read-entire-file.fs
Normal file
4
Task/Read-entire-file/F-Sharp/read-entire-file.fs
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
// read entire file into variable using default system encoding or with specified encoding
|
||||
open System.IO
|
||||
let data = File.ReadAllText(filename)
|
||||
let utf8 = File.ReadAllText(filename, System.Text.Encoding.UTF8)
|
||||
7
Task/Read-entire-file/Factor/read-entire-file.factor
Normal file
7
Task/Read-entire-file/Factor/read-entire-file.factor
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
USING: io.encodings.ascii io.encodings.binary io.files ;
|
||||
|
||||
! to read entire file as binary
|
||||
"foo.txt" binary file-contents
|
||||
|
||||
! to read entire file as lines of text
|
||||
"foo.txt" ascii file-lines
|
||||
8
Task/Read-entire-file/Fantom/read-entire-file.fantom
Normal file
8
Task/Read-entire-file/Fantom/read-entire-file.fantom
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
class ReadString
|
||||
{
|
||||
public static Void main (Str[] args)
|
||||
{
|
||||
Str contents := File(args[0].toUri).readAllStr
|
||||
echo ("contents: $contents")
|
||||
}
|
||||
}
|
||||
1
Task/Read-entire-file/Forth/read-entire-file.fth
Normal file
1
Task/Read-entire-file/Forth/read-entire-file.fth
Normal file
|
|
@ -0,0 +1 @@
|
|||
s" foo.txt" slurp-file ( str len )
|
||||
14
Task/Read-entire-file/Fortran/read-entire-file-1.f
Normal file
14
Task/Read-entire-file/Fortran/read-entire-file-1.f
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
program read_file
|
||||
implicit none
|
||||
integer :: n
|
||||
character(:), allocatable :: s
|
||||
|
||||
open(unit=10, file="read_file.f90", action="read", &
|
||||
form="unformatted", access="stream")
|
||||
inquire(unit=10, size=n)
|
||||
allocate(character(n) :: s)
|
||||
read(10) s
|
||||
close(10)
|
||||
|
||||
print "(A)", s
|
||||
end program
|
||||
22
Task/Read-entire-file/Fortran/read-entire-file-2.f
Normal file
22
Task/Read-entire-file/Fortran/read-entire-file-2.f
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
program file_win
|
||||
use kernel32
|
||||
use iso_c_binding
|
||||
implicit none
|
||||
|
||||
integer(HANDLE) :: hFile, hMap, hOutput
|
||||
integer(DWORD) :: fileSize
|
||||
integer(LPVOID) :: ptr
|
||||
integer(LPDWORD) :: charsWritten
|
||||
integer(BOOL) :: s
|
||||
|
||||
hFile = CreateFile("file_win.f90" // c_null_char, GENERIC_READ, &
|
||||
0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL)
|
||||
filesize = GetFileSize(hFile, NULL)
|
||||
hMap = CreateFileMapping(hFile, NULL, PAGE_READONLY, 0, 0, NULL)
|
||||
ptr = MapViewOfFile(hMap, FILE_MAP_READ, 0, 0, 0)
|
||||
|
||||
hOutput = GetStdHandle(STD_OUTPUT_HANDLE)
|
||||
s = WriteConsole(hOutput, ptr, fileSize, transfer(c_loc(charsWritten), 0_c_intptr_t), NULL)
|
||||
s = CloseHandle(hMap)
|
||||
s = CloseHandle(hFile)
|
||||
end program
|
||||
10
Task/Read-entire-file/FreeBASIC/read-entire-file.basic
Normal file
10
Task/Read-entire-file/FreeBASIC/read-entire-file.basic
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
' FB 1.05.0 Win64
|
||||
|
||||
Open "input.txt" For Input Encoding "ascii" As #1
|
||||
Dim fileLen As LongInt = Lof(1) '' get file length in bytes
|
||||
Dim buffer As String = Space(fileLen) '' allocate a string of size 'fileLen' bytes
|
||||
Get #1, 1, buffer '' read all data from start of file into the buffer
|
||||
Print buffer '' print to console
|
||||
buffer = "" '' release memory used by setting buffer to empty
|
||||
Close #1
|
||||
Sleep
|
||||
2
Task/Read-entire-file/Frink/read-entire-file.frink
Normal file
2
Task/Read-entire-file/Frink/read-entire-file.frink
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
a = read["file:yourfile.txt"]
|
||||
b = read["file:yourfile.txt", "UTF-8"]
|
||||
29
Task/Read-entire-file/FutureBasic/read-entire-file.basic
Normal file
29
Task/Read-entire-file/FutureBasic/read-entire-file.basic
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
_window = 1
|
||||
begin enum 1
|
||||
_scrollView
|
||||
_textView
|
||||
end enum
|
||||
|
||||
void local fn BuildWindow
|
||||
CGRect r = {0,0,550,400}
|
||||
window _window, @"Read Entire File", r
|
||||
scrollview _scrollView, r
|
||||
ViewSetAutoresizingMask( _scrollView, NSViewWidthSizable + NSViewHeightSizable )
|
||||
textview _textView,, _scrollView
|
||||
end fn
|
||||
|
||||
local fn ReadTextFile
|
||||
CFStringRef string
|
||||
CFURLRef url = openpanel 1, @"Select text file..."
|
||||
if ( url )
|
||||
string = fn StringWithContentsOfURL( url, NSUTF8StringEncoding, NULL )
|
||||
TextSetString( _textView, string )
|
||||
else
|
||||
// user cancelled
|
||||
end if
|
||||
end fn
|
||||
|
||||
fn BuildWindow
|
||||
fn ReadTextFile
|
||||
|
||||
HandleEvents
|
||||
3
Task/Read-entire-file/GAP/read-entire-file.gap
Normal file
3
Task/Read-entire-file/GAP/read-entire-file.gap
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
InputTextFile("input.txt");
|
||||
s := ReadAll(f);; # two semicolons to hide the result, which may be long
|
||||
CloseStream(f);
|
||||
1
Task/Read-entire-file/GUISS/read-entire-file.guiss
Normal file
1
Task/Read-entire-file/GUISS/read-entire-file.guiss
Normal file
|
|
@ -0,0 +1 @@
|
|||
Start,Programs,Accessories,Notepad,Menu:File,Open,Doubleclick:Icon:Notes.TXT,Button:OK
|
||||
6
Task/Read-entire-file/Gambas/read-entire-file.gambas
Normal file
6
Task/Read-entire-file/Gambas/read-entire-file.gambas
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
Public Sub Form_Open()
|
||||
Dim sFile As String
|
||||
|
||||
sFile = File.Load(User.home &/ "file.txt")
|
||||
|
||||
End
|
||||
21
Task/Read-entire-file/Genie/read-entire-file.genie
Normal file
21
Task/Read-entire-file/Genie/read-entire-file.genie
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
[indent=4]
|
||||
/*
|
||||
Read entire file, in Genie
|
||||
|
||||
valac readEntireFile.gs
|
||||
./readEntireFile [filename]
|
||||
*/
|
||||
|
||||
init
|
||||
|
||||
fileName:string
|
||||
fileContents:string
|
||||
fileName = (args[1] is null) ? "readEntireFile.gs" : args[1]
|
||||
|
||||
try
|
||||
FileUtils.get_contents(fileName, out fileContents)
|
||||
except exc:Error
|
||||
print "Error: %s", exc.message
|
||||
return
|
||||
|
||||
stdout.printf("%d bytes read from %s\n", fileContents.length, fileName)
|
||||
4
Task/Read-entire-file/Go/read-entire-file-1.go
Normal file
4
Task/Read-entire-file/Go/read-entire-file-1.go
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
import "io/ioutil"
|
||||
|
||||
data, err := ioutil.ReadFile(filename)
|
||||
sv := string(data)
|
||||
27
Task/Read-entire-file/Go/read-entire-file-2.go
Normal file
27
Task/Read-entire-file/Go/read-entire-file-2.go
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
// +build !windows,!plan9,!nacl // These lack syscall.Mmap
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"log"
|
||||
"os"
|
||||
"syscall"
|
||||
)
|
||||
|
||||
func main() {
|
||||
f, err := os.Open("file")
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
fi, err := f.Stat()
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
data, err := syscall.Mmap(int(f.Fd()), 0, int(fi.Size()),
|
||||
syscall.PROT_READ, syscall.MAP_PRIVATE)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
fmt.Println(string(data))
|
||||
}
|
||||
1
Task/Read-entire-file/Groovy/read-entire-file.groovy
Normal file
1
Task/Read-entire-file/Groovy/read-entire-file.groovy
Normal file
|
|
@ -0,0 +1 @@
|
|||
def fileContent = new File("c:\\file.txt").text
|
||||
2
Task/Read-entire-file/Haskell/read-entire-file-1.hs
Normal file
2
Task/Read-entire-file/Haskell/read-entire-file-1.hs
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
do text <- readFile filepath
|
||||
-- do stuff with text
|
||||
4
Task/Read-entire-file/Haskell/read-entire-file-2.hs
Normal file
4
Task/Read-entire-file/Haskell/read-entire-file-2.hs
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
eagerReadFile :: FilePath -> IO String
|
||||
eagerReadFile filepath = do
|
||||
text <- readFile filepath
|
||||
last text `seq` return text
|
||||
1
Task/Read-entire-file/Icon/read-entire-file-1.icon
Normal file
1
Task/Read-entire-file/Icon/read-entire-file-1.icon
Normal file
|
|
@ -0,0 +1 @@
|
|||
every (fs := "") ||:= |reads(1000000)
|
||||
3
Task/Read-entire-file/Icon/read-entire-file-2.icon
Normal file
3
Task/Read-entire-file/Icon/read-entire-file-2.icon
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
every put(fL := [],|FUNC(read()))
|
||||
every (fs := "") ||:= !fL || "\n"
|
||||
fL := &null
|
||||
7
Task/Read-entire-file/Inform-7/read-entire-file.inf
Normal file
7
Task/Read-entire-file/Inform-7/read-entire-file.inf
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
Home is a room.
|
||||
|
||||
The File of Testing is called "test".
|
||||
|
||||
When play begins:
|
||||
say "[text of the File of Testing]";
|
||||
end the story.
|
||||
2
Task/Read-entire-file/J/read-entire-file-1.j
Normal file
2
Task/Read-entire-file/J/read-entire-file-1.j
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
require 'files' NB. not needed for J7 & later
|
||||
var=: fread 'foo.txt'
|
||||
2
Task/Read-entire-file/J/read-entire-file-2.j
Normal file
2
Task/Read-entire-file/J/read-entire-file-2.j
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
require 'jmf'
|
||||
JCHAR map_jmf_ 'var';'foo.txt'
|
||||
10
Task/Read-entire-file/Jakt/read-entire-file.jakt
Normal file
10
Task/Read-entire-file/Jakt/read-entire-file.jakt
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
fn main() {
|
||||
let filename = "Read_entire_file.jakt"
|
||||
mut file = File::open_for_reading(filename)
|
||||
mut builder = StringBuilder::create()
|
||||
for byte in file.read_all() {
|
||||
builder.append(byte)
|
||||
}
|
||||
let contents = builder.to_string()
|
||||
println("{}", contents)
|
||||
}
|
||||
22
Task/Read-entire-file/Java/read-entire-file-1.java
Normal file
22
Task/Read-entire-file/Java/read-entire-file-1.java
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
import java.io.BufferedReader;
|
||||
import java.io.FileReader;
|
||||
import java.io.IOException;
|
||||
|
||||
public class ReadFile {
|
||||
public static void main(String[] args) throws IOException{
|
||||
String fileContents = readEntireFile("./foo.txt");
|
||||
}
|
||||
|
||||
private static String readEntireFile(String filename) throws IOException {
|
||||
FileReader in = new FileReader(filename);
|
||||
StringBuilder contents = new StringBuilder();
|
||||
char[] buffer = new char[4096];
|
||||
int read = 0;
|
||||
do {
|
||||
contents.append(buffer, 0, read);
|
||||
read = in.read(buffer);
|
||||
} while (read >= 0);
|
||||
in.close();
|
||||
return contents.toString();
|
||||
}
|
||||
}
|
||||
20
Task/Read-entire-file/Java/read-entire-file-2.java
Normal file
20
Task/Read-entire-file/Java/read-entire-file-2.java
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
import java.nio.channels.FileChannel.MapMode;
|
||||
import java.nio.MappedByteBuffer;
|
||||
import java.io.RandomAccessFile;
|
||||
import java.io.IOException;
|
||||
import java.io.File;
|
||||
|
||||
public class MMapReadFile {
|
||||
public static void main(String[] args) throws IOException {
|
||||
MappedByteBuffer buff = getBufferFor(new File(args[0]));
|
||||
String results = new String(buff.asCharBuffer());
|
||||
}
|
||||
|
||||
public static MappedByteBuffer getBufferFor(File f) throws IOException {
|
||||
RandomAccessFile file = new RandomAccessFile(f, "r");
|
||||
|
||||
MappedByteBuffer buffer = file.getChannel().map(MapMode.READ_ONLY, 0, f.length());
|
||||
file.close();
|
||||
return buffer;
|
||||
}
|
||||
}
|
||||
1
Task/Read-entire-file/Java/read-entire-file-3.java
Normal file
1
Task/Read-entire-file/Java/read-entire-file-3.java
Normal file
|
|
@ -0,0 +1 @@
|
|||
String content = new Scanner(new File("foo"), "UTF-8").useDelimiter("\\A").next();
|
||||
15
Task/Read-entire-file/Java/read-entire-file-4.java
Normal file
15
Task/Read-entire-file/Java/read-entire-file-4.java
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
import java.util.List;
|
||||
import java.nio.charset.Charset;
|
||||
import java.nio.file.*;
|
||||
|
||||
public class ReadAll {
|
||||
public static List<String> readAllLines(String filesname){
|
||||
Path file = Paths.get(filename);
|
||||
return Files.readAllLines(file, Charset.defaultCharset());
|
||||
}
|
||||
|
||||
public static byte[] readAllBytes(String filename){
|
||||
Path file = Paths.get(filename);
|
||||
return Files.readAllBytes(file);
|
||||
}
|
||||
}
|
||||
5
Task/Read-entire-file/JavaScript/read-entire-file-1.js
Normal file
5
Task/Read-entire-file/JavaScript/read-entire-file-1.js
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
var fso=new ActiveXObject("Scripting.FileSystemObject");
|
||||
var f=fso.OpenTextFile("c:\\myfile.txt",1);
|
||||
var s=f.ReadAll();
|
||||
f.Close();
|
||||
try{alert(s)}catch(e){WScript.Echo(s)}
|
||||
14
Task/Read-entire-file/JavaScript/read-entire-file-2.js
Normal file
14
Task/Read-entire-file/JavaScript/read-entire-file-2.js
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
var file = document.getElementById("fileInput").files.item(0); //a file input element
|
||||
if (file) {
|
||||
var reader = new FileReader();
|
||||
reader.readAsText(file, "UTF-8");
|
||||
reader.onload = loadedFile;
|
||||
reader.onerror = errorHandler;
|
||||
}
|
||||
function loadedFile(event) {
|
||||
var fileString = event.target.result;
|
||||
alert(fileString);
|
||||
}
|
||||
function errorHandler(event) {
|
||||
alert(event);
|
||||
}
|
||||
1
Task/Read-entire-file/Jq/read-entire-file-1.jq
Normal file
1
Task/Read-entire-file/Jq/read-entire-file-1.jq
Normal file
|
|
@ -0,0 +1 @@
|
|||
jq -R -s . input.txt
|
||||
1
Task/Read-entire-file/Jq/read-entire-file-2.jq
Normal file
1
Task/Read-entire-file/Jq/read-entire-file-2.jq
Normal file
|
|
@ -0,0 +1 @@
|
|||
jq -R . input.txt | jq -s .
|
||||
1
Task/Read-entire-file/Jq/read-entire-file-3.jq
Normal file
1
Task/Read-entire-file/Jq/read-entire-file-3.jq
Normal file
|
|
@ -0,0 +1 @@
|
|||
jq -R -s 'split("\n")' input.txt
|
||||
1
Task/Read-entire-file/Jsish/read-entire-file.jsish
Normal file
1
Task/Read-entire-file/Jsish/read-entire-file.jsish
Normal file
|
|
@ -0,0 +1 @@
|
|||
var contents = File.read("filename")
|
||||
1
Task/Read-entire-file/Julia/read-entire-file-1.julia
Normal file
1
Task/Read-entire-file/Julia/read-entire-file-1.julia
Normal file
|
|
@ -0,0 +1 @@
|
|||
read("/devel/myfile.txt", String) # read file into a string
|
||||
1
Task/Read-entire-file/Julia/read-entire-file-2.julia
Normal file
1
Task/Read-entire-file/Julia/read-entire-file-2.julia
Normal file
|
|
@ -0,0 +1 @@
|
|||
A = Mmap.mmap(open("/devel/myfile.txt"), Array{UInt8,1})
|
||||
1
Task/Read-entire-file/K/read-entire-file-1.k
Normal file
1
Task/Read-entire-file/K/read-entire-file-1.k
Normal file
|
|
@ -0,0 +1 @@
|
|||
`c$1:"example.txt"
|
||||
1
Task/Read-entire-file/K/read-entire-file-2.k
Normal file
1
Task/Read-entire-file/K/read-entire-file-2.k
Normal file
|
|
@ -0,0 +1 @@
|
|||
0:"example.txt"
|
||||
1
Task/Read-entire-file/KAP/read-entire-file-1.kap
Normal file
1
Task/Read-entire-file/KAP/read-entire-file-1.kap
Normal file
|
|
@ -0,0 +1 @@
|
|||
content ← io:readFile "file.txt"
|
||||
1
Task/Read-entire-file/KAP/read-entire-file-2.kap
Normal file
1
Task/Read-entire-file/KAP/read-entire-file-2.kap
Normal file
|
|
@ -0,0 +1 @@
|
|||
content ← io:read "file.txt"
|
||||
5
Task/Read-entire-file/Kotlin/read-entire-file.kotlin
Normal file
5
Task/Read-entire-file/Kotlin/read-entire-file.kotlin
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
import java.io.File
|
||||
|
||||
fun main(args: Array<String>) {
|
||||
println(File("unixdict.txt").readText(charset = Charsets.UTF_8))
|
||||
}
|
||||
1
Task/Read-entire-file/LFE/read-entire-file.lfe
Normal file
1
Task/Read-entire-file/LFE/read-entire-file.lfe
Normal file
|
|
@ -0,0 +1 @@
|
|||
(set `#(ok ,data) (file:read_file "myfile.txt"))
|
||||
1
Task/Read-entire-file/Lang5/read-entire-file.lang5
Normal file
1
Task/Read-entire-file/Lang5/read-entire-file.lang5
Normal file
|
|
@ -0,0 +1 @@
|
|||
'foo.txt slurp
|
||||
2
Task/Read-entire-file/Lasso/read-entire-file.lasso
Normal file
2
Task/Read-entire-file/Lasso/read-entire-file.lasso
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
local(f) = file('foo.txt')
|
||||
#f->readString
|
||||
|
|
@ -0,0 +1,7 @@
|
|||
filedialog "Open a Text File","*.txt",file$
|
||||
if file$<>"" then
|
||||
open file$ for input as #1
|
||||
entire$ = input$(#1, lof(#1))
|
||||
close #1
|
||||
print entire$
|
||||
end if
|
||||
13
Task/Read-entire-file/Lingo/read-entire-file.lingo
Normal file
13
Task/Read-entire-file/Lingo/read-entire-file.lingo
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
----------------------------------------
|
||||
-- Reads whole file, returns string
|
||||
-- @param {string} tFile
|
||||
-- @return {string|false}
|
||||
----------------------------------------
|
||||
on readFile (tFile)
|
||||
fp = xtra("fileIO").new()
|
||||
fp.openFile(tFile, 1)
|
||||
if fp.status() then return false
|
||||
res = fp.readFile()
|
||||
fp.closeFile()
|
||||
return res
|
||||
end
|
||||
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