The third program of software Engineering: "WC Project"--File information statistics (Word Count) command-line program

Source: Internet
Author: User

The third program of software Engineering: "WC Project"--File information statistics (Word Count) command-line program

Format: Wc.exe [Parameter][filename]

In [parameter], the user interacts with the program through input parameters, the following functions are required:

1. Basic functions

Supports the-c statistic file character number
Supports-W statistics file Word count
Supports-l statistics file Total rows


2, expand the function

Support-A returns advanced options (line of code lines with blank lines of comment)
Supports-s recursive processing of eligible files


3. Advanced Features

Support for the-X program to interact with users in a graphical interface

[FileName] is the file name to be processed.

Basic functions

A string string is used in the main function to receive user input and decomposed into a parameter array and a file address.

Write the Basecount () function to read the file, count the number of characters per row, and record the number of rows, while using the StringBuffer class to record all the information in the file. Finally, the number of statistical words, to avoid the word by line, the punctuation is counted as a word.

Write the response () function according to the user input parameters output information, where the program regardless of the user input parameters, all in the reading of the file all the information is recorded and saved, the user input parameters in what output what.

Java program can be called in the Cmd.exe to run, lifting the bigger, the output of the results

The contents of 123.txt on the desktop are as follows:

Using System;namespace oneprogram{    class program        {    console.write ("Wc.exe");}    }

Expansion capabilities

The use of parameter- s is: Parameter with "-S", the file name is "*.xxx", output all. XXX file information.

It is equivalent to find all the files in the directory, then determine the type of file, and then the matching file for file information statistics, the final output.

Then write a responsefors () function to specifically handle the parameter with "-S" command, first record other parameters, separate the file path and file type, define the string array record file path of all the filenames, and the user input file type comparison, the file information for the matching file statistics, output; cycle comparison output;

Results of the output

The effect of parameter-A is as follows: The parameter has "-a", the blank line of the output file, the code line, the comment line statistic information.

This function is similar to the basic function and is rewritten directly in the Basecount () function, and the function name is changed to Baseandadvancecount ().

The length of the line is judged when the program reads the line, whether it is a blank line, and whether there is a continuous "/" to determine if it is a comment line, or a line of code if it is neither a blank line nor a comment line.

Results of the output

The contents of 123.txt on the desktop are changed to:

Using System;namespace oneprogram{////    class program    {    console.write ("Wc.exe");}    } Without copyright

Advanced Features

The use of the parameter- x is: Enter only "-X", pop-up File selection dialog box, select the file after the output of all the information.

Here is still the parameter "-X" to establish a separate function Responseforx (), Create a File selection dialog box, select a file to return the absolute path to the file, to the Baseandadvancecount () function and the Response () function. Output all information.

Results of the operation process and output

The content in 123.txt on the desktop has not changed.

At this point all functions have been basically implemented:)

All the code has been uploaded to Coding,coding: First wait ...

J.x.dinosaur

The third program of software Engineering: "WC Project"--File information statistics (Word Count) command-line program

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.