java - 此代码应该写入文件但没有
问题描述
public String updateTasks(String oldBean, String catName,String taskname1)
{
File inputFile = new File(catName+".todo");
File tempFile = new File("myTempFile.todo2");
BufferedReader reader1 = null ;//
BufferedWriter writer1 = null;//
String lineToEdit = taskname1;
String currentLine;
try {
writer1=new BufferedWriter(new FileWriter(tempFile));
reader1=new BufferedReader(new FileReader(inputFile));
}
catch (IOException e)
{
e.printStackTrace();
}
try {
while((currentLine = reader1.readLine()) != null) {
String[] sa = currentLine.split(":");
if(sa[0].equals(lineToEdit))
{
writer1.write(oldBean+ System.getProperty("line.separator"));
//continue;
}
writer1.write(currentLine + System.getProperty("line.separator"));//this //is supposed to write to a file
返回常量.SUCCESS;
}
} catch (IOException e) {
e.printStackTrace();
System.out.println("error occurred....");
}
return null;
}
此方法应该写入 myTempFile.todo1 但不会写入任何内容。文件创建正常,但不写任何东西。因为 write dobt 返回任何东西,所以没有办法检查。
解决方案
推荐阅读
- javascript - 修改模板内容失败
- java - jdbc:前端java,后端Oracle 10g express版
- angular - 打字稿版本 3.7.2 和 Angular
- combinations - 在概率上相同的项目被视为不同的项目?
- node.js - 如何将 vuejs - express 应用程序部署到本地 Ubuntu?
- node.js - 我的 API 的删除部分有什么问题?
- c++ - 为什么在这种情况下使用 new 和 std::unique_ptr 会导致崩溃?
- java - Spring Throws "ERROR SqlExceptionHelper: Already closed" after timeout
- android - 如何在 Android 中有效清除 Edittext
- html - href 到子域重定向到文件夹而不是子域