This is a program that allows the user to search for an item and then the program splits the items and stores them in 4 different textfields. However, below is a method for updating the retrieved items back to the file. The problem is whenever the user clicks on the update button, the line does update successfully, but the other lines in the file are deleted!

Iam using an arraylist to store the searched item and also temporary file to write the item and then renaming it.

Can someone help me please. Thanks in advance!

Code:
file.txt

ramal hotel1  10 uk

bren  hotel2  20 france

gil   hotel3  30 china

Code:
//Update to file
button9.addActionListener(new ActionListener(){
public  void actionPerformed(ActionEvent ae){

    try {

    String stringSearch = textfield1.getText();

    File filetemp = File.createTempFile("TempFileName", ".tmp", new File("/"));
    BufferedWriter writer = new BufferedWriter(new FileWriter(filetemp));
    File file = new File("file.txt");
    BufferedReader bf = new BufferedReader(new FileReader(file));


    int linecount = 0;
              String line;

    ArrayList<String> list = new ArrayList<String>();
    while (( line = bf.readLine()) != null){
    list.add(line);
    linecount++;


    int indexfound = line.indexOf(stringSearch);

    if (indexfound > -1) {

    String a = textfield1.getText();
    String b = textfield2.getText();
    String c = textfield3.getText();
    String d = textfield4.getText();




    String[] word = line.split("\t");
    String firstword = word[0];
    String secondword = word[1];
    String thirdword = word[2];
    String fourthword = word[3];




    writer.write(line.replace("\t", "\t").replace(firstword, b).replace(secondword, c).replace(thirdword, d));
    writer.flush();

    }

    writer.newLine();
    }
    writer.close();
    bf.close();
    filetemp.renameTo(file);
    filetemp.deleteOnExit();


    FileChannel src = new FileInputStream(filetemp).getChannel();
    FileChannel dest = new FileOutputStream(file).getChannel();
    dest.transferFrom(src, 0, src.size());



    }catch (IOException e) {

    System.out.println("IO Error Occurred: " + e.toString());

    }

}
});