我在工程下面写了一个专门处理数据的类如下:
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.util.ArrayList;public class OpenFile {

//保存数据;
public static void setData(ArrayList al){
ObjectOutputStream ops = null;
try {
 ops = new ObjectOutputStream(new FileOutputStream("data/data.txt"));
 ops.writeObject(al);
}catch (IOException e) {
System.out.println("保存数据出错");
}finally{
try {
ops.close();
} catch (IOException e) {
System.out.print("保存数据出错");
}
}
}

//读取数据;
public static ArrayList getData(){
ArrayList al = null;
ObjectInputStream oips = null;
try {
oips = new ObjectInputStream(new FileInputStream("data/data.txt"));
al= (ArrayList)oips.readObject();

}catch(FileNotFoundException ffe){
ObjectOutputStream ops = null;
try {
ops = new ObjectOutputStream(new FileOutputStream("data/data.txt"));
ArrayList arl = new ArrayList();
ops.writeObject(arl);
return arl;

} catch (FileNotFoundException e) {
System.out.println("创建文件的失败");
} catch (IOException e) {
e.printStackTrace();
}finally{
try{
if(ops != null){
ops.close();
}
}catch(IOException ioe){
System.out.println("创建文件的链接关闭失败");
}
}

}catch(IOException ioe){
System.out.print("获取数据出错");
} catch (ClassNotFoundException e) {

e.printStackTrace();
}finally{
try{
if(oips != null){
oips.close();
}
}catch(IOException ioe){

}
}
return al;
}
}
然后工程下的其中一个类总是取到这个类下的getData()的返回值(是一个ArrayList)的第一个值作为初始界面,现存在一问题,
如果我是第一次运行此程序在硬盘上还没生成这个文件时,getData()的返回值就应该是我在getData()方法下初始化的一个ArrayList();,显然这个ArrayList是空的,我设想判断这个值是空的然后禁用调用的这个类,从而跳过错误,但是确不行,求指教,