Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8020749
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T21:46:36+00:00 2026-06-04T21:46:36+00:00

I am trying to write a program that will take a text file with

  • 0

I am trying to write a program that will take a text file with commands such as insert, delete and sort and have them insert or delete a node from a linked list. So far I have been able to tokenize the strings and write them out; but I also want to use if statements whether the text line says to insert or if it says delete. This is what I have so far. Thank you for any help.

(lane.txt)

         insert 1

         insert 7

         insert 5

         delete 7

         insert 2

         insert 4

         delete 5

And the code:

import java.io.;
import java.util.
;

class 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

} // end class

The output:

Action: insert
Key Value: 1

Action: insert
Key Value: 7

Action: insert
Key Value: 5

Action: delete
Key Value: 7

Action: insert
Key Value: 2

Action: insert
Key Value: 4

Action: delete
Key Value: 5

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T21:46:38+00:00Added an answer on June 4, 2026 at 9:46 pm

    Strings should be compared using equals:

    if (action.equals("insert")) { // etc.
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to write a program that will take an HTML file and make
I'm trying to write a program that will read from a flat file of
I am trying to write a fragment program that will take a texture and
I am trying to write a program that will take the users input value
Im trying to write a program in C++ that will take 2 files and
I'm trying to write a program that will delete a set of files/folders that
Im trying to write a simple program that will take 2 multi line inputs
Hey there. I'm trying to write a small program that will read the four
I'm trying to write a program that takes a large file (of any type)
I'm trying to write a program that could monitor multiple folders for file creations

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.