your code is not doing what it should because in line
line = line.replaceAll("/.*?/", "/"+raw2+"/");
string from reference "line" doesn't match regex, therefore it doesn't replace
here is what your need
if (line.contains("downstream_rm(j,l)")) {
String replacement = line;
while (!replacement.matches(".*?/.*?/.*?")) {
replacement += scanner.nextLine();
}
String raw = "";
for (int index = 0; index < strarray.size(); index++) {
String s = strarray.get(index);
raw = raw + "\n" + s;
}
String raw2 = raw.replaceAll(",", "");
line = replacement.replaceAll("/.*?/", "/" + raw2 + "/");
}
just make sure your "raw2" variable points to right String object, and in result variable line will contain replaced string