private void saveCurrent() { PrintWriter writer = null; try { writer = new PrintWriter("config.txt", "UTF-8"); writer.println("PhoneNumbers:"); for (String s : Main.getEmails()) { writer.println(s); } writer.println("Items:"); for (Item s : Main.getItems()) { writer.println(s.getName() + "," + s.getWebsite()); } results.setText("Current settings have been saved sucessfully."); } catch (FileNotFoundException e1) { e1.printStackTrace(); } catch (UnsupportedEncodingException e1) { e1.printStackTrace(); } writer.close(); }
// 读写的方法 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(); } }
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()); }
private void displayInformation() { results.setText("-Cell Phones-\n"); if (Main.getEmails().isEmpty()) { results.append("\nNo Numbers"); } else { ArrayList<String> emails = Main.getEmails(); int index = 0; for (String s : emails) { index++; results.append("\n(" + index + ") " + s); } } results.append("\n\n-Current Items-"); if (Main.getItems().isEmpty()) { results.append("\n\nNo Items"); } else { ArrayList<Item> items = Main.getItems(); int index = 0; for (Item i : items) { String s = i.getWebsite().substring(46, i.getWebsite().length()); index++; for (int j = 0; j < s.length(); j++) { if (s.substring(j, j + 1).equals("&")) { s = s.substring(0, j); } } results.append("\n\n(" + index + ")\nName: \t" + i.getName() + "\nItem: \t" + s); } results.append("\n\n"); } }