Globally replace text in several files: Difference between revisions

Added Kotlin
No edit summary
(Added Kotlin)
Line 706:
end
end</lang>
 
=={{header|Kotlin}}==
<lang scala>// version 1.2.0
 
import java.io.File
 
fun main(args: Array<String>) {
val files = arrayOf("file1.txt", "file2.txt")
for (file in files) {
val f = File(file)
var text = f.readText()
println(text)
text = text.replace("Goodbye London!", "Hello New York!")
f.writeText(text)
println(f.readText())
}
}</lang>
 
{{out}}
<pre>
File1 contains "Goodbye London!"
 
File1 contains "Hello New York!"
 
File2 contains "Goodbye London!"
 
File2 contains "Hello New York!"
</pre>
 
=={{header|Lasso}}==
9,482

edits