my goal is to copy the identical content of a file, replace some words and write the content in a new file.
I don't understand the problem, it takes the content correctly except for the line breaks. It also recognizes multiple consecutive white spaces but does not take the new line. Here the code i wrote for it:
public class FileDefinition {
String result = "";
String pathxml = pathxmlin;
String pathconf = pathfileconf;
//func to be recalled in the main for the different files
public String getPropValues() throws IOException {
try {
Properties prop = new Properties();
String pathconf = this.pathconf;
String pathxml = this.pathxml;
//Read file conf
File inputFile = new File(pathconf);
InputStream is = new FileInputStream(inputFile);
BufferedReader br = new BufferedReader(new InputStreamReader(is));
//load the buffered file
prop.load(br);
// get the property value and print it out
String name = prop.getProperty("name");
String loc = prop.getProperty("location");
String id = prop.getProperty("PropID");
//Read scxml file to get the format
FileReader reader = new FileReader(pathxml);
//research fields to be changed
String searchname = "RotaionToInside";
String searchlocation = "location";
String searchpropid = "PropOfJobID";
String newString;
StringBuffer str = new StringBuffer();;
BufferedReader rb = new BufferedReader(reader);
while ((newString = rb.readLine()) != null){
str.append(newString.replaceAll(searchlocation, loc));
str.append(newString.replaceAll(searchpropid, id));
str.append(newString.replaceAll(searchname, name));
}
rb.close();
String pathwriter = pathxml + name + ".scxml";
BufferedWriter bw = new BufferedWriter(new FileWriter(new File(pathscxmlout)));
bw.write(str.toString());
//flush the stream
bw.flush();
//close the stream
bw.close();
} catch (Exception e) {
System.out.println("Exception: " + e);
}
return result;
}
}