예제 #1
0
 // 读写的方法
 public void Save() {
   try {
     file.delete();
     FileWriter writer = new FileWriter(file);
     for (Item i : list)
       writer.write(
           i.getNumber()
               + ";"
               + i.getCategory()
               + ";"
               + i.getName()
               + ";"
               + i.getModel()
               + ";"
               + i.getStock()
               + "\n");
     writer.close();
   } catch (Exception e) {
     e.printStackTrace();
   }
 }
예제 #2
0
 public void show() {
   Collections.sort(
       list,
       new Comparator<Item>() {
         public int compare(Item i1, Item i2) {
           if (i1.getNumber() > i2.getNumber()) return 1;
           else return -1;
         }
       });
   for (Item i : list)
     System.out.println(
         i.getNumber()
             + ";"
             + i.getCategory()
             + ";"
             + i.getName()
             + ";"
             + i.getModel()
             + ";"
             + i.getStock());
 }