0

Hi I am using below code to read the file just after update the same. The file i.e. FileA.txt stored in resource folder

public void dataSetup() throws SQLException, IOException {

        InputStream input = TestHelper.class.getClassLoader().getResourceAsStream("FileA.txt");

        Scanner s = new Scanner(input).useDelimiter("\\A");
        String result = s.hasNext() ? s.next() : "";
        result = result.replace("oldtext", "newText");


        FileOutputStream fileOut = new FileOutputStream("FileA.txt",false);

        fileOut.write(result.getBytes());
        fileOut.flush();
        fileOut.close();

        readData("FileA.txt");

}

    public void readData(String myFile) throws IOException, SQLException {

        InputStream inputSql = TestHelper.class.getClassLoader().getResourceAsStream(myFile);
        String runSql = new String(inputSql.readAllBytes());

    }

With above code I can see updated string in result, but after check the runSql string still the original string (before update).

Shabar
  • 2,617
  • 11
  • 57
  • 98
  • `FileOutputStream fileOut = new FileOutputStream("FileA.txt",false);` is going to create a new file in the "current working" location (that is, the place the program was executed from). I'd also be considered about the ability to update anything in the "resources" folder, as this suggests that this location will become embedded after the project is built which would make it read only – MadProgrammer Jun 27 '21 at 00:49
  • Exactly. The "files" are not the same, and you're not updating the "resource" in any fashion (nor can you, without resorting to dirty kludges) – Hovercraft Full Of Eels Jun 27 '21 at 00:51

0 Answers0