I don't think the standard Java library provides anything ready-built to do this (though I did a quick search and it looks like a few people have had a go at implementing sed in Java). In fact,
sed -i does create a new temporary file, outputs the modifications to it, then overwrites the original. You can see this if you attempt to use it in a folder in which you do not have write permissions:
Code:
rob:secdir$ sed -i "s/$/ $date/" file
sed: couldn't open temporary file ./sedXlilKP: Permission denied
... In other words,
Code:
sed -i "s/$/ $date/" file
is equivalent to:
Code:
sed "s/$/ $date/" file > tmp_file && mv tmp_file file
You could, of course, read the contents of the file into an ArrayList, append the timestamp to each element of this, and then truncate the file and write the data back again (so long as it was not too large to hold efficiently in memory).