public class ProductManageSystem {
ArrayList<Product> al = new ArrayList<Product>();
BufferedReader bin;
File file;
boolean continue_e = true;
boolean bFlag;
String tmpID;
ObjectInputStream fin;
ObjectOutputStream fout;
int position;
Product firstProduct, tmpProduct;
ProductManageSystem() {
try {
file = new File("src/文件/Product.txt");
fout = new ObjectOutputStream(new FileOutputStream(file, true));
firstProduct = new Product("2000", "hello");
al.add(firstProduct);
fout.writeObject(al);
fout.close();
bin = new BufferedReader(new InputStreamReader(System.in));
} catch (IOException e) {
}
}
public boolean searchID(String proID) {
// 检查系统中是否已经存在编号为stuID的记录
try {
fin = new ObjectInputStream(new FileInputStream(file));
al = (ArrayList) fin.readObject();
fin.close();
} catch (Exception e) {
}
for (position = 0; position < al.size(); position++) {
tmpProduct = (Product) al.get(position);
if (tmpProduct.getNo().equalsIgnoreCase(proID)) {
break;
}
}// for
if (al.size() != 0 && position != al.size()) {// 找到了满足条件的记录
return true;
}
else
return false;// 未找到满足条件的记录
}
public int searchStudByID(String idStr) {
//
try {
fin = new ObjectInputStream(new FileInputStream(file));
al = (ArrayList) fin.readObject();
fin.close();
} catch (Exception e) {
}
for (position = 0; position < al.size(); position++) {
tmpProduct = (Product) al.get(position);
if (tmpProduct.getNo().equalsIgnoreCase(idStr)) {
break;
}
}// for
return position;
}