为什么我的file.renameTo(newFile)不起作用?

时间:2015-10-09 06:14:42

标签: java file applet rename record

}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();
        }

这是我的Applet程序的一部分。当找到用户输入的记录时,该标志将等于1。当用户单击标记= 1的“确定”按钮时,它将执行此部分。我不知道为什么,但它继续打印,“重命名失败”。

请帮帮我。我马上就需要这个。

0 个答案:

没有答案