Q: Why does my file.renameTo(newFile) doesn't work? }else if(ae.getSource()==btnOk&&flag==1){
            name = txtName.getText();
            yr = txtYear.getText();
            sec = txtSect.getText();
            grdP = txtGraP.getText();
            grades [0] = txtMath.getText();
            grades [1] = txtEngl.getText();
            grades [2] = txtFili.getText();
            grades [3] = txtScie.getText();
            grades [4] = txtAraP.getText();
            try {
                fwTemp = new FileWriter(fylTemp, true);
                bwTemp = new BufferedWriter(fwTemp);
                bwTemp.write(name+" "+yr+" "+sec+" ");
                for (int i = 0; i<5; i++) {
                    bwTemp.write(grades[i]+" ");
                }
                bwTemp.write(grdP);
                bwTemp.newLine();
                bwTemp.flush();
            } catch(Exception e) {
                System.out.println(e);
            }
            bwTemp.close();
            fwTemp.close();
            fyl.delete();
            JOptionPane.showMessageDialog (null, "Your record has successfuly edited!", "Success", JOptionPane.WARNING_MESSAGE);
            if(fylTemp.renameTo(new File("Student_Record.txt"))) {
                System.out.print("The file has renamed successfuly!");
            } else {
                System.out.print("Rename failed!");
            }
            setEmpty();
            DISABLE();
            setState();
        }

This is a part of my Applet program. When a record that was entered by a user was found, the flag will be equals to one. As the user click the "Ok" button with the flag = 1, it will perform this part. I don't know why but it keeps on printing, "Rename failed".
Help me please. I need this immediately.
