Question

So, now you are asked to write a Java program to process topprobe.dat in the following way: • It deletes the last line contai

Sample from my tcpprobe.dat file to use for testing (Ignore that giant gap its all supposed to be one block):

*Note* xxxxx=51811, yyyyy = 51812, zzzzz = 51810 according to the data below

33.530532341 10.10.1.2:51811 10.10.2.2:5001 32 0x7ef44c9e 0x7ef3db7e 21 15 185856 193 29312
33.542474133 10.10.1.2:51811 10.10.2.2:5001 32 0x7ef457ee 0x7ef3e126 21 15 185856 193 29312
33.554576589 10.10.1.2:51811 10.10.2.2:5001 32 0x7ef457ee 0x7ef3e6ce 21 15 185856 194 29312
33.566356665 10.10.1.2:51811 10.10.2.2:5001 32 0x7ef4633e 0x7ef3ec76 21 15 185856 194 29312
33.578419057 10.10.1.2:51811 10.10.2.2:5001 32 0x7ef4633e 0x7ef3f21e 21 15 185856 195 29312

33.818567133 10.10.1.2:51812 10.10.2.2:5001 32 0x27767e39 0x2775eb29 27 19 336000 195 29312
33.830336654 10.10.1.2:51812 10.10.2.2:5001 32 0x27768989 0x2775f0d1 27 19 336000 195 29312
33.854344478 10.10.1.2:51812 10.10.2.2:5001 32 0x27768989 0x2775f679 27 19 336000 196 29312
33.878463548 10.10.1.2:51812 10.10.2.2:5001 32 0x277694d9 0x277601c9 27 19 336000 196 29312
33.902536919 10.10.1.2:51812 10.10.2.2:5001 32 0x2776a029 0x27760d19 27 19 336000 196 29312
33.926261724 10.10.1.2:51812 10.10.2.2:5001 32 0x2776ab79 0x27761869 27 19 336000 196 29312
33.950479934 10.10.1.2:51812 10.10.2.2:5001 32 0x2776b6c9 0x277623b9 27 19 336000 197 29312
33.962389651 10.10.1.2:51810 10.10.2.2:5001 32 0x38f9ae1 0x38f1e71 22 16 272256 192 29312
33.974309947 10.10.1.2:51810 10.10.2.2:5001 32 0x38f9ae1 0x38f2419 22 16 272256 193 29312
33.986437149 10.10.1.2:51810 10.10.2.2:5001 32 0x38fa631 0x38f29c1 22 16 272256 194 29312
33.998376239 10.10.1.2:51810 10.10.2.2:5001 32 0x38fa631 0x38f2f69 22 16 272256 194 29312
34.010376480 10.10.1.2:51810 10.10.2.2:5001 32 0x38fb181 0x38f3511 22 16 272256 195 29312
34.022182438 10.10.1.2:51810 10.10.2.2:5001 32 0x38fb181 0x38f3ab9 22 16 272256 196 29312
34.034363788 10.10.1.2:51810

Can someone please write this java code. I rate if the code compiles and gives the correct output. Thank you in advance!!

0 0
Add a comment Improve this question Transcribed image text
Answer #1

***Please upvote if you liked the answer***

Screenshot of the Java code:-

import java.io. BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; import java

Demo:-

Input:-

0 O X topprobe.dat - Notepad File Edit Format View Help 33.530532341 10.10.1.2:51811 10.10.2.2:5001 32 Ox7ef44c9e Ox7ef3db7e

Output of the file tcpprobe_51810_comma.data:-

x topprobe_51810_comma.dat - Notepad File Edit Format View Help 33.962389651,10.10.1.2:51810,10.10.2.2:5001, 32,0x38f9ae1, 0x

Java code to copy:-

import java.io.BufferedWriter;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.util.Scanner;

public class Process_TCPProbe_YourInitial{

   public static void main(String[] args) throws IOException {
      
       //Extracting the port numbers from the file names passed in the arguments
       String portNumber1 = args[1].substring(9, 14);
       String portNumber2 = args[2].substring(9, 14);
       String portNumber3 = args[3].substring(9, 14);
              
       int i = 0;
       Scanner s = new Scanner(new FileReader(args[0]));
       //Initialising array of contents with length equals to number of lines in the input file
       String[] contents = new String[18];      
       while(true)
       {
           if (i == 18)
               break;//Skipping the last line of the file
           //Replaces the whitespace with comma and stores in the string array
           contents[i] = s.nextLine().replace(" ", ",");
          
           i++;  
       }
      
       BufferedWriter bw1 = new BufferedWriter(new FileWriter(args[1]));
       BufferedWriter bw2 = new BufferedWriter(new FileWriter(args[2]));
       BufferedWriter bw3 = new BufferedWriter(new FileWriter(args[3]));
       //Iterating the array of contents using a for each loop
       for(String each:contents)
       {
           //Writing the string to the corresponding file which matches with the portNumber
           //along with a new line
           if (each.contains(portNumber1))
           {
               bw1.write(each);
               bw1.newLine();
              
           }
           else if(each.contains(portNumber2))
           {
               bw2.write(each);
               bw2.newLine();
              
           }
           else if(each.contains(portNumber3))
           {
               bw3.write(each);
               bw3.newLine();
              
           }
       }
       //This is necessary to finally output the text from the buffer to the corresponding file
       bw1.flush();
       bw2.flush();
       bw3.flush();
      
       //Closing all the file reading and writing handles
       bw1.close();
       bw2.close();
       bw3.close();
       s.close();
   }

}

Add a comment
Know the answer?
Add Answer to:
Sample from my tcpprobe.dat file to use for testing (Ignore that giant gap its all supposed...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Objective : Write a C Shell script which copies all files(*.java and *.class) from your home dire...

    Objective : Write a C Shell script which copies all files(*.java and *.class) from your home directory to a new one, and Analyze the new directory information such as number of files, user permissions, and disk usage. Sample Output:                                                    << CS Directory Analysis >>      Date:   ============================================================ Current Directory: /home/tomss New Directory Created : /home/tomss/pgm01 File information Total Number of files : 22 files Directory files:   0 files Plain text files:   10 files File have read permissions: 3 files File have...

  • data: (copy and paste in excel to view columns in alignment) Sample   Repair Time (days) 1  ...

    data: (copy and paste in excel to view columns in alignment) Sample   Repair Time (days) 1   12 2   17 3   9 4   16 5   10 6   18 7   12 8   14 9   15 10   14 11   14 12   8 13   11 14   10 15   8 16   8 17   14 18   12 19   14 20   13 21   12 22   15 23   15 24   10 25   24 26   17 27   13 28   15 29   13 30   15 31   36 32   40 33  ...

  • Write a Java program that will read in this XLS file and store them in an...

    Write a Java program that will read in this XLS file and store them in an ArrayList or LinkedList or HashMap Ask user to input what country they wish to search for and then output the country population. Also ask user which other countries they wish to compare. then compare the two countries by outputting both country population NOTE: THIS IS AN XLS FILE F9 Population 1 Country 2 31056997 3581655 32930091 57794 71201 12127071 13477 69108 39921833 2976372 71891...

  • Java programming How do i change this program to scan data from file and find the...

    Java programming How do i change this program to scan data from file and find the sum of the valid entry and count vaild and invalid entries The provided data file contains entries in the form ABCDE BB That is - a value ABCDE, followed by the base BB. Process this file, convert each to decimal (base 10) and determine the sum of the decimal (base 10) values. Reject any entry that is invalid. Report the sum of the values...

  • The purpose of this assignment is to develop solutions that perform File IO and objects. Problem specifications are shown below with my changes in blue. 1. File Previewer Write a program that asks...

    The purpose of this assignment is to develop solutions that perform File IO and objects. Problem specifications are shown below with my changes in blue. 1. File Previewer Write a program that asks the user for the name of a text file. The program should display the first 10 lines of the file on the screen. If the file has fewer than 10 lines, the entire file should be displayed along with a message indicating the entire file has been...

  • 1 Objective Build a hashing algorithm that is suitable for use in a Bloom Filter. Please...

    1 Objective Build a hashing algorithm that is suitable for use in a Bloom Filter. Please note that while a cryptographic hash is quite common in many Bloom Filters, the hashing algorithm to be implemented is a mix of the the following algorithmic models, specifically, a multiply & rotate hash colloquially known as a murmur hash, and an AND, rolale, & XOR hash colloquially known as an ARX hash. 2 Requirements • Inputs. Read the input file which contains strings...

  • For an Independent t-test, you can either: Perform all calculations by typing in formulas to compute...

    For an Independent t-test, you can either: Perform all calculations by typing in formulas to compute the needed components and answers You can use the "Data: Data Analysis: t-test: Two Sample Assuming Equal Variances" procedure Examples of this procedure can be found in your text, Excel Appendix 10.1, p. 459 For a Paired Differences t-test (dependent t-test), you can either Perform all calculations by typing in formulas to compute the needed components and answer. You can use the "Data: Data...

  • [C++] Using Files—Total and Average Rainfall Write a program that reads in from a file a...

    [C++] Using Files—Total and Average Rainfall Write a program that reads in from a file a starting month name, an ending month name, and then the monthly rainfall for each month during that period. As it does this, it should sum the rainfall amounts and then report the total rainfall and average rainfall for the period. For example, the output might look like this: During the months of March–June the total rainfall was 7.32 inches and the average monthly rainfall...

  • Review Questions 1. What three transaction cycles exist in all businesses? 2. Name the major subsystems...

    Review Questions 1. What three transaction cycles exist in all businesses? 2. Name the major subsystems of the expenditure cycle. 3. Identify and distinguish between the physical and financial components of the expenditure cycle. 4. Name the major subsystems of the conversion cycle. 5. Name the major subsystems of the revenue cycle. 6. Name the three types of documents 7. Name the two types of journals. 8. Distinguish between a general journal and journal vouchers 9. Name the two types...

  • Computer Science Problem C++ cla5a.cpp 1 // cla10a BY student name, CSCI 2170-section 2 //File: cla10a.cpp...

    Computer Science Problem C++ cla5a.cpp 1 // cla10a BY student name, CSCI 2170-section 2 //File: cla10a.cpp 3 //Author: Dr. Roland H. Untch 4 //Purpose: This program displays a student's classification 5 // (e.g., "freshman", "sophmore", etc.) based on an 6 // integer classification code that is read in. In 7 // it's current form, this program uses nested IF 8 // statements to encode a "multiway branch" or "case 9 // construct" to determine the student's classification. 10 // As...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT