File input/output: Difference between revisions
Content added Content deleted
m (alphabetized list) |
|||
Line 145:
}
}</lang>
=={{header|Batch File}}==▼
<lang dos>copy input.txt output.txt</lang>▼
or▼
<lang dos>type input.txt > output.txt</lang>▼
or▼
<lang dos>for /f "" %L in ('more^<input.txt') do echo %L>>output.txt</lang>▼
there may be other techniques too.▼
=={{header|BASIC}}==
Line 166 ⟶ 157:
CLOSE #2
SYSTEM</lang>
▲=={{header|Batch File}}==
▲<lang dos>copy input.txt output.txt</lang>
▲or
▲<lang dos>type input.txt > output.txt</lang>
▲or
▲<lang dos>for /f "" %L in ('more^<input.txt') do echo %L>>output.txt</lang>
=={{header|Befunge}}==
Line 716:
READ(FIle=input, CLoSe=1) c
WRITE(FIle=output, CLoSe=1) c END</lang>
=={{header|Icon}} and {{header|Unicon}}==▼
{{works with|Unicon}}▼
Icon and Unicon I/O by default is line driven. This can be changed with options in open and by the use of reads() and writes().▼
<lang Icon>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</lang>▼
=={{header|IDL}}==
Line 731 ⟶ 740:
; that's all
close,/all</lang>
▲=={{header|Icon}} and {{header|Unicon}}==
▲{{works with|Unicon}}
▲Icon and Unicon I/O by default is line driven. This can be changed with options in open and by the use of reads() and writes().
▲<lang Icon>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</lang>
=={{header|J}}==
Line 956:
.echo -a Myfilename.txt contains: $read(myfilename.txt,1)
}</lang>
=={{header|Objective-C}}==▼
{{works with|Cocoa}}▼
{{works with|GNUstep}}▼
Read the contents of input.txt and place it in output.txt, creating a file if needed:▼
<lang objc>NSData *data = [NSData dataWithContentsOfFile:@"input.txt"];▼
[data writeToFile:@"output.txt" atomically:YES];</lang>▼
Displayed without error checking to make it more clear. In real code you will need to add lot of error checking code, and maybe use <tt>dataWithContentsOfFile:error:</tt> if you want to get error information on failure. However, this code will mostly work correctly even if input does not exist or is not accessible. <tt>dataWithContentsOfFile:</tt> will return nil, and sending nil the message <tt>writeTofile:atomically:</tt> does nothing :-)▼
The second argument (<tt>atomically:YES</tt>) write the content to a temporary file, and rename the temporary file to the destination file, replacing existing file.▼
=={{header|Objeck}}==
Line 993 ⟶ 978:
}
}</lang>
▲=={{header|Objective-C}}==
▲{{works with|Cocoa}}
▲{{works with|GNUstep}}
▲Read the contents of input.txt and place it in output.txt, creating a file if needed:
▲<lang objc>NSData *data = [NSData dataWithContentsOfFile:@"input.txt"];
▲[data writeToFile:@"output.txt" atomically:YES];</lang>
▲Displayed without error checking to make it more clear. In real code you will need to add lot of error checking code, and maybe use <tt>dataWithContentsOfFile:error:</tt> if you want to get error information on failure. However, this code will mostly work correctly even if input does not exist or is not accessible. <tt>dataWithContentsOfFile:</tt> will return nil, and sending nil the message <tt>writeTofile:atomically:</tt> does nothing :-)
▲The second argument (<tt>atomically:YES</tt>) write the content to a temporary file, and rename the temporary file to the destination file, replacing existing file.
=={{header|OCaml}}==
Line 1,277:
<lang R>file.copy("input.txt", "output.txt", overwrite = FALSE)</lang>
=={{header|REBOL}}==▼
<lang REBOL>write %output.txt read %input.txt▼
; No line translations:▼
write/binary %output.txt read/binary %input.txt▼
; Save a web page:▼
write/binary %output.html read http://rosettacode.org▼
</lang>▼
=={{header|Retro}}==▼
<lang Retro>with files'▼
here dup "input.txt" slurp "output.txt" spew</lang>▼
=={{header|RapidQ}}==
Line 1,332 ⟶ 1,318:
=={{header|Raven}}==
<lang raven>'input.txt' read 'output.txt' write</lang>
▲=={{header|REBOL}}==
▲<lang REBOL>write %output.txt read %input.txt
▲; No line translations:
▲write/binary %output.txt read/binary %input.txt
▲; Save a web page:
▲write/binary %output.html read http://rosettacode.org
▲</lang>
▲=={{header|Retro}}==
▲<lang Retro>with files'
▲here dup "input.txt" slurp "output.txt" spew</lang>
=={{header|REXX}}==
|