在我的项目中,我需要为每个学生创建一个文件,我认为我已经创建了方法,如下所示
public addStudent(String fullName, int grn, String formClass, String formTeacher)
{
//Default values
int creativity = 0;
int action = 0;
int service = 0;
int total = 0;
//Initialize File
RandomAccessFile adding = new RandomAccessFile(new File(fullName + ".dat"), "rw");
long fileSize = adding.length();
adding.seek(fileSize);
//Variables from Method
adding.writeUTF(fullName + "\n");
adding.writeInt(grn + "\n");
adding.writeUTF(formClass + "\n");
adding.writeUTF(formTeacher + "\n");
//Variables created in method
adding.writeInt(creativtiy + "\n");
adding.writeInt(action + "\n");
adding.writeInt(service + "\n");
adding.writeInt(total + "\n");
adding.close();
}
我只是一直认为这是不对的,并希望对某些部分进行澄清,例如这条线
RandomAccessFile adding = new RandomAccessFile(new File(fullName + ".dat"), "rw");
fullname 是传递给方法的变量,它是学生的姓名和姓氏(例如:John Lennon)。我想要做的是有一个名为“John Lennon.dat”的文件。但是我一直认为我在这里的方法是错误的。
另一个问题是关于整数值。它们会不时更新,但只需简单地添加 current+new。我怎么做?