Join Slack
Powered by
How would you write a Kotlin script that replace a...
# announcements
j
jmfayard
10/07/2019, 11:03 AM
How would you write a Kotlin script that replace all occurrences of a string in a file, overwriting the file i.e. in-place like sed:
$ sed -e 's/find/replace/' -e 's/find/replace/' filename
m
Matteo Mirk
10/07/2019, 11:08 AM
If the file is not too big you can read it all into memory, replace occurrences and write it back as a whole. If the file is big and memory or cpu usage is a problem you should consider using
http://docs.oracle.com/javase/8/docs/api/java/nio/MappedByteBuffer.html
3
Views
Open in Slack
Previous
Next