📄 store.java
字号:
/* * Store.java * The package functions contains the different class executing the different functions of the FlightSystem Reservation. */package reservation.system.functions;import java.io.*;/** * This class hold Create structure. This object allows to create a new flight in the data base by calling the method <CODE>create</CODE> in {@link reservation.system.FlightSystem}. * @author Texier Mathieu and Frederic Bidon */public class Store extends Functions { /**Name of the file where we want to save the data.*/ private File datafile; /** * Verify invariants : * <PRE> * - Argument not null * - The number of argument equals 1 * - File's name doesn't exist * - The file can be created * </PRE> * @throws Exception if the file exists or cannot be created. */ void _check (String[] arg) throws Exception { CheckFlightListNotEmpty (); ArgumentIsValid (arg, 1, 1); File datafile = new File (arg[0]); if (!datafile.exists ()) { if (!datafile.createNewFile ()) throw new Exception ("Cannot create the file: " + datafile.getPath ()); } else throw new Exception ("file " + datafile.getPath () + " already exist"); this.datafile = datafile; } /** * Display the usage for the command <CODE>reload</code>. * @return the usage. */ static public String usage() { String usage = " Usage command Store: store <fileName>\n\r"; usage += " - The <fileName> is the path to the file to be store \n\r"; usage +=" The file extention is .out .\n"; return usage; } /** * Store in a file the data contained in the database. * @throws Exception if the file is not saved. * @return a confimation's message if the data are stored. */ public String execute () throws Exception { ObjectOutputStream fout = new ObjectOutputStream (new FileOutputStream (datafile)); fout.writeObject (fs); return "Flight stored"; }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -