File input/output: Difference between revisions
Content added Content deleted
(→{{header|Groovy}}: ++ fortran) |
(→{{header|Tcl}}: show how to do it with fcopy, add formatting) |
||
Line 999: | Line 999: | ||
{{works with|tixwish}} |
{{works with|tixwish}} |
||
<lang tcl>set in [open "input.txt" r] |
|||
set out [open "output.txt" w] |
|||
# Obviously, arbitrary transformations could be added to the data at this point |
|||
puts -nonewline $out [read $in] |
|||
⚫ | |||
close $in |
|||
close $out</lang> |
|||
For larger files, it is better to use the <tt>fcopy</tt> command, though in general this restricts what operations can be performed rather more (only encoding and end-of-line translations are possible, though not shown here): |
|||
⚫ | |||
set out [open "output.txt" w] |
|||
fcopy $in $out |
|||
⚫ | |||
close $out</lang> |
|||
Or the minimal version if we don't need any processing of the data at all: |
|||
<lang tcl>file copy input.txt output.txt</lang> |
|||
Other File I/O: |
Other File I/O: |
||
<lang tcl>#open file for writing |
|||
set myfile [open "README.TXT" w] |
|||
#write something to the file |
|||
puts $myfile "This is line 1, so hello world...." |
|||
#close the file |
|||
close $myfile</lang> |
|||
⚫ | |||
set myfile [open "README.TXT" r] |
|||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
#close the file |
|||
⚫ | |||
close $myfile</lang> |
|||
close $myfile |
|||
=={{header|Toka}}== |
=={{header|Toka}}== |