File input/output: Difference between revisions

Content added Content deleted
(Added Clean example)
No edit summary
Line 46: Line 46:
[[Category:AppleScript]]
[[Category:AppleScript]]
on copyFile from src into dst
on copyFile from src into dst
set filedata to read file src
set filedata to read file src
set outfile to open for access dst with write permission
set outfile to open for access dst with write permission
write filedata to outfile
write filedata to outfile
close access outfile
close access outfile
end copyFile
end copyFile
Line 639: Line 639:
if (!$in=fopen('input.txt','r')) {
if (!$in=fopen('input.txt','r')) {
die('Could not open input.txt!');
die('Could not open input.txt!');
}
}
if (!$out=fopen('output.txt','w')) {
if (!$out=fopen('output.txt','w')) {
die('Could not open output.txt!');
die('Could not open output.txt!');
}
}
while(!feof($in)) {
while(!feof($in)) {
$data = fread($in,512);
$data = fread($in,512);
fwrite($out,$data);
fwrite($out,$data);
}
}
Line 658: Line 658:
<?php
<?php
if( $contents = file_get_contents('input.txt') ){
if( $contents = file_get_contents('input.txt') ){
if( !file_put_contents('output.txt') ) echo('could not write output file');
if( !file_put_contents('output.txt') ) echo('could not write output file');
}else{
}else{
echo('could not open input file');
echo('could not open input file');
}
}
?>
?>

==[[Pop11]]==
[[Category:Pop11]]

Char by char copy:

lvars i_stream = discin('input.txt');
lvars o_stream = discout('output.txt');
lvars c;
while (i_stream() ->> c) /= termin do
o_stream(c);
endwhile;

Low level block copy:

lvars i_file = sysopen('input.txt', 0, true);
lvars o_file = syscreate('output.txt', 1, true);
lvars buff = inits(4096);
lvars i;
while (sysread(i_file, buff, length(buff)) ->> i) > 0 do
syswrite(o_file, buff, i);
endwhile;


==[[Python]]==
==[[Python]]==