我有一个库存管理系统,它读取 Items 和 Stores 的 .txt 文件和一个名为 Stocks 的桥实体,并输出一个 .txt 文件,该文件显示基于这三个文件的信息。
它在底部。
public class Ims {
private static Logger LOG = Logger.getLogger(Ims.class);
public static void main(String[] args) throws Exception {
PropertyConfigurator.configure("log.properties");
LOG.debug("main()");
File itemsFile = new File("items.txt");
File storesFile = new File("stores.txt");
File stockFile = new File("stocks.txt");
if (!itemsFile.exists()) {
LOG.error("Required 'items.txt' is missing");
} else if (!storesFile.exists()) {
LOG.error("Required 'stores.txt' is missing");
}
new Ims(itemsFile, storesFile, stockFile);
}
public Ims(File itemsFile, File storesFile, File stockFile) {
LOG.debug("Ims()");
HashMap<String, Item> items = null;
HashMap<String, Store> stores = null;
List<Stock> stocks = null;
try {
items = InventoryReader.read(itemsFile);
stores = StoresReader.read(storesFile);
stocks = StockReader.read(stockFile);
} catch (ApplicationException e) {
LOG.error(e.getMessage());
return;
}
// Collections.sort(items, new CompareByPrice()); <-- this should sort it. How do I do this as a command line argument?
File inventory = new File("inventory.txt");
PrintStream out = null;
try {
out = new PrintStream(new FileOutputStream(inventory));
InventoryReport.write(items, stores, stocks, out);
} catch (FileNotFoundException e) {
LOG.error(e.getMessage());
}
}
}
我希望能够使用命令行参数以多种方式对读取的参数进行排序。
例如:
java –jar Ims.jar by_value desc total
我该怎么做?