java - How to read contents of a template file make changes and save as new file? -


i have file lets call template.cfg , want make changes , save file new name preserving template file.

template file contents. there alot more in file these online lines i'm concerned about.

<property>url</property> <property>password</property> <property>schema</property> <property>user</property> 

output file want have new name lets call databaseinfo.cfg i'd need search words url , replace user defined url same password schema , user. save in same directory template.

<property>foo</property> <property>bar</property> <property>d2d</property> <property>d2duser</property> 

i'm thinking in terms save as. not sure how should go modifying file without changing original , yet saving new file.

i dont have code yet outside of getting template files full path open file because i'm curious best route take having file.

file file = new file(template.cfg); string fullpath = file.getabsolutepath(); 

you can simultaneously run scanner read text old file, modify text using string manipulation operations, , use printwriter write output strings new file. way, have both old file , new file.

alternatively, if text replacements particularly straightforward, away java altogether , manipulate on unix command line "sed" command. hope helps.


Comments

Popular posts from this blog

html - Sizing a high-res image (~8MB) to display entirely in a small div (circular, diameter 100px) -

java - IntelliJ - No such instance method -

identifier - Is it possible for an html5 document to have two ids? -