[Java] How to append something to each line in a text file ?
Hello everyone,
I am thinking of appending something to each line in a text file with Java. I prefer not write a new file with content appended from the old one. That 'something' would probably be Time Stamp when the file is created (which is same for each line). I am not sure Java provide some easy way for it or not. Appreciate any idea from you guys, Thanks in advance, -Kun |
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 Code:
sed -i "s/$/ $date/" file Code:
sed "s/$/ $date/" file > tmp_file && mv tmp_file file |
Thanks, Rob! I think I will take this instead of Javaing.
Quote:
|
Well, most if not all of that can be done if you learn java regular expressions.
|
All times are GMT -5. The time now is 05:42 PM. |