如何解决更新后立即读取文件
嗨,我正在使用下面的代码在更新后读取文件。存储在资源文件夹中的文件,即 FileA.txt
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());
}
使用上面的代码,我可以在 result
中看到更新的字符串,但在检查 runsql
字符串后仍然是原始字符串(更新前)。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。