首页 > 解决方案 > 此代码应该写入文件但没有

问题描述

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 返回任何东西,所以没有办法检查。

标签: javamodel-view-controllerfile-io

解决方案


推荐阅读