我正在尝试调用创建文件的方法,但是我从执行的操作中调用该方法,它根本不能抛出 IOException ...
这是代码:
/* ACTION PERFORMED**/
public void actionPerformed(ActionEvent evt){
Object source = evt.getSource();
if (source == add)
{
String mothername = " ";
String fathername = " ";
String motherphone = " ";
String fatherphone = " ";
Patient patient = new Patient(...));
printPatients(patient);
System.out.println("past printing patient");
writetoFile(patient); //giving an error
}
if (source == uadd)
{
Patient patient = new Patient(...));
printPatients(patient);
writetoFile(patient); //giving an error
}
}
//This is the method I am trying to call
public static void writetoFile(Patient p) throws IOException
{
RandomAccessFile inout = new RandomAccessFile("PatientsInfo.dat", "rw");
inout.seek(inout.length());
inout.writeUTF(p.getName());
inout.writeUTF(p.getAge());
inout.writeUTF(p.getGender());
inout.writeUTF(p.getSiblings());
inout.writeUTF(p.getID());
inout.writeUTF(p.getNationality());
inout.writeUTF(p.getCivilStatus());
inout.writeUTF(p.getProfession());
inout.writeUTF(p.getPhone1());
inout.writeUTF(p.getPhone2());
inout.writeUTF(p.getEmail());
inout.writeUTF(p.getMotherName());
inout.writeUTF(p.getFatherName());
inout.writeUTF(p.getMotherPhone());
inout.writeUTF(p.getFatherPhone());
inout.writeUTF(p.getMedication());
inout.writeUTF(p.getDoctorsName());
inout.writeUTF(p.getFrequency());
inout.writeUTF(p.getPrice());
System.out.println("names and sentinel value sent to file Countries.dat");
inout.close();
}
//错误在两条蓝线中,它显示的错误是:
Error: C:\Users\Pedro Quintas\Documents\Documents and Work
\Escola\Computer Science\Programs\Dossier\AddPatient.java:362:
unreported exception java.io.IOException; must be caught or
declared to be thrown
请告诉我要改变什么