Hello!
I'm new to this site and fairly new to Java, I've tried creating a program that takes a file as input and edits specific substrings in said file, compiles without problems but the file remains unchanged.
import java.io.*;
public class Uppg10_OH {
static class MinHistoria {
private String namnInfil;
private String gammaltNamn;
private String nyttNamn;
public MinHistoria(String inFilNamn, String gNamn, String nNamn) {
namnInfil = inFilNamn;
gammaltNamn = gNamn;
nyttNamn = nNamn;
}
public void transformera() throws IOException {
try {
FileInputStream stream = new FileInputStream("C:\\test.txt");
DataInputStream in = new DataInputStream(stream);
BufferedReader br = new BufferedReader( new InputStreamReader(in));
String stringRad;
while ((stringRad = br.readLine()) != null) {
if (stringRad.contains(gammaltNamn)) {
stringRad.replaceAll(gammaltNamn, nyttNamn);
}
}
in.close();
br.close();
}
catch (Exception e) {
System.err.println("Error: " + e.getMessage());
}
}
public static void main (String args[]) throws IOException {
MinHistoria mh = new MinHistoria("C:\\test.txt", "cat", "dog");
mh.transformera();
}
}
}
I'm not quite sure where the problem lies, any help would be greatly appreciated!