Click to See Complete Forum and Search --> : Java Code help


alidar777
09-25-2006, 12:31 PM
I have bunch of files in my directory, i need to replace a date string 98/12/07 to 1998/12/07. How will i do it using Java can any body please help
Thanks.
If there is any other sol using shell script that will also help

chazzy
09-25-2006, 12:43 PM
are these dates in the files though or where are these dates?

PineSolPirate
09-25-2006, 12:43 PM
Java seems like a rather big solution to a little problem. What OS are you on.

Also, are they all needing to become 1998, or are there other years inside them too?

:)

alidar777
09-25-2006, 01:12 PM
thanks, Yes all these dates are in the file and all of them need to be changed to 1998

Waylander
09-25-2006, 08:52 PM
I had this when I last wrote a data parser, when migrating some excel worksheets to mysql.

For the dates I did something like this:

String [] stringDate= s.split("-");

values[0] = (Integer.parseInt(values[1])>=50) ? "19"+values[0] : "20"+values[0];


Just read the file one line at a time, make changes and output the new lines to a new file. Do each line's processing within a try catch so you can reject the row, and within the catch block output it to a seperate error file.

Waylander.

agent_x91
09-28-2006, 08:25 AM
Java seems like a rather big solution to a little problem.
:)

I agree... if you just want to replace a set string with another set string, you can simply use the Find and Replace feature of a program such as Notepad. There's no need to create a java application at all. ;)