Make a backup file: Difference between revisions
Added Kotlin
(Add Julia language) |
(Added Kotlin) |
||
Line 264:
println(io, "this task was solved during a talk about rosettacode at the PyCon China in 2011")
end</lang>
=={{header|Kotlin}}==
{{trans|Java}}
<lang scala>// version 1.1.51
import java.io.File
fun saveWithBackup(fileName: String, vararg data: String) {
val orig = File(fileName)
// canonicalPath follows symlinks to their ends
val backup = File(orig.canonicalPath + ".backup")
orig.renameTo(backup)
val pw = orig.printWriter()
for (i in data.indices) {
pw.print(data[i])
if (i < data.lastIndex) pw.println()
}
pw.close()
}
fun main(args: Array<String>) {
saveWithBackup("original.txt", "fourth", "fifth", "sixth")
}</lang>
Contents of 'original.txt' ''before'' the program is run and of 'original.txt.backup' ''after'' it is run:
<pre>
first
second
third
</pre>
Contents of 'original.txt' ''after'' the program is run:
<pre>
fourth
fifth
sixth
</pre>
=={{header|Lasso}}==
|