挿入、削除、並べ替えなどのコマンドを含むテキストファイルを取得し、リンクリストからノードを挿入または削除するプログラムを作成しようとしています。これまでのところ、文字列をトークン化して書き出すことができました。ただし、テキスト行に挿入するか、削除するかを示すifステートメントも使用します。これは私がこれまでに持っているものです。助けてくれてありがとう。
(lane.txt)
insert 1
insert 7
insert 5
delete 7
insert 2
insert 4
delete 5
そしてコード:
java.ioをインポートします。; java.utilをインポートします。;
クラスTokenTest{
public static void main (String[] args) {
TokenTest tt = new TokenTest();
tt.dbTest();
}
void dbTest() {
DataInputStream dis = null;
String dbRecord = null;
try {
File f = new File("lane.txt");
FileInputStream fis = new FileInputStream(f);
BufferedInputStream bis = new BufferedInputStream(fis);
dis = new DataInputStream(bis);
// read the first record of the database
while ( (dbRecord = dis.readLine()) != null) {
StringTokenizer st = new StringTokenizer(dbRecord, " ");
String action = st.nextToken();
String key = st.nextToken();
System.out.println("Action: " + action);
if(action == "insert")
{
System.out.println("holla");
}
System.out.println("Key Value: " + key);
if(action == "delete")
{
System.out.println("holla");
}
System.out.println(" ");
}
} catch (IOException e) {
// catch io errors from FileInputStream or readLine()
System.out.println("Uh oh, got an IOException error: " + e.getMessage());
} finally {
// if the file opened okay, make sure we close it
if (dis != null) {
try {
dis.close();
} catch (IOException ioe) {
System.out.println("IOException error trying to close the file: ");
}
} // end if
} // end finally
} // end dbTest
}//クラスを終了
出力:
アクション:キー値の挿入:1
アクション:キー値の挿入:7
アクション:キー値の挿入:5
処置:キー値を削除してください:7
アクション:キー値を挿入します:2
アクション:キー値の挿入:4
処置:キー値を削除してください:5