Java中如何用输入的新的字符串替换一个旧的字符串,将改变后的文本保存到一个新的文件中。
2条回答 默认 最新
- 皮蛋不吃粥 2022-05-24 17:31关注
参考下
String oldStr = "test"; Scanner scanner = new Scanner(System.in); oldStr = scanner.nextLine(); File file = new File("D:/tmp", "word.txt"); try { if (!file.exists()) { file.createNewFile(); } FileOutputStream output = new FileOutputStream(file); output.write(oldStr.getBytes()); output.close(); } catch (IOException e) { e.printStackTrace(); }
本回答被题主选为最佳回答 , 对您是否有帮助呢?解决 1无用