此代码应该写入文件,但不会

时间:2019-05-13 18:02:05

标签: java model-view-controller file-io

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

return Constants.SUCCESS;

}
} catch (IOException e) {
e.printStackTrace();
System.out.println("error occurred....");
}

return null;






    }

该方法应该写入myTempFile.todo1,但不会写入     任何东西。     文件创建好了,但是什么也没写。     由于write dosbt返回任何内容,因此无法检查。

0 个答案:

没有答案