CommandLine is a static class that provides an easy way to parse command-line arguments. The CommandLine interface provides an enumeration for the accepted options, and the subclasses Options and DefaultParser provide concrete implementations of this interface. Both Options and DefaultParser implement the ParseException interface, which is an alternative to exceptions. This document is a reference to all the classes in the classes-for-java.com library, and how they interact together. It is based on Java SE version 1.5. The classes-for-java.com library is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. The classes-for-java.com library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with the classes-for-java.com library. If not, see (You should be able to obtain a copy of the license from the license webpage.) Copyright 2002-2007 by Tom Tromey All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. 3. Any name of a contributor other than the author may not be used to endorse or promote products derived from this software without specific prior written permission. Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. See the attached README.txt file for a description of the classes in this
-n: Minimum filename (the most common short option) -a: Additional files to process (if there are additional files they are added after -e: Maximum output file size (in kilobytes) -i: Maximum number of input files to read at once (in files) -o: Output file (if there is an output file, it's placed here) -l: Maximum number of links to process (if there are additional links they are added after the specified -i: Input file (if there is an input file, it is read into this file) -s: Symbolic links to follow (if there are additional symbolic links, they are added after the specified) -j: Process the 'java' command first (This option is only available when using the 'java' launcher) -m: String of commands to execute (these are assumed to be in order. Comma or semicolon separated) -c: command line parameters --help: Displays the help text -h: Displays the help text CommandLine createArgs: The createArgs method creates an arg list from the command line (after the '--' option is encountered). The createArgs method will make sure all options are accounted for. For example, the -a option may be given several times, or there may be more files than the -i option allows. createArgs will fix this problem. The createArgs method will also clean up some of the prefixes on your argument list. The output of the createArgs method is the arg list in the form of a String. The createArgs method prints the error if there is one. If the method is successful, the arg list can be manipulated or accessed by the user. createArgs example: // Create the arg list from the command line String[] cmdLineArgs = CommandLine.getArgs(); // Tell CommandLine to handle this many input files CommandLine.setMaximumInputFiles(10); // If this is an output file, create an output string if (cmdLineArgs[0].startsWith("-")) { OutputStream outputStream = new FileOutputStream(cmdLineArgs[0]); // Create an OutputStream from the input file FileInputStream inputStream = new FileInputStream(cmdLineArgs[1]); // Now we create a string of all the input files that have been b78a707d53
CommandLine allows you to specify a list of files to work with by parsing command line parameters and from the java.util.List type. It works out which files need to be parsed, and passes on the list of files (in particular directory entries, which is convenient for cases where you only want to work on a subdirectory) to your own code for processing. It also does a few simple things on its own: it parses an entire command line into tokens (without itself doing a "scan", it just passes the tokens on to its own processing code), it throws exceptions if there are problems with the input, and it does some rudimentary error checking. Examples: Use CommandLine.add() to add a file to the list to work with. CommandLine.add("-subdir", "recipes") adds the recipes directory to the list to work with. CommandLine.setDirectory() sets the current directory to work from. CommandLine.setFileNamePattern() sets the file name pattern that will match file names to add to the list. CommandLine.add() and CommandLine.setFileNamePattern() can be combined to add only files that match a file name pattern. CommandLine.add() and CommandLine.setDirectory() can be combined to add all files in a given directory to the list. Properties: CommandLine takes a Map of the following properties: inputDirectory : The path to a directory to work from If CommandLine is invoked with the -subdir option, this is the subdirectory to work from inputFileNamePattern : The pattern to match against filenames outputDirectory : The path to where files will be written If CommandLine is invoked with the -output option, this is the output directory outputFileNamePattern : The pattern to match against filenames If CommandLine is invoked with the -output option, this is the output filename pattern quiet : If set to false, output warnings to stdout Input directories are specified with the classpath, so you need to give the classpath containing the CommandLine package as input
This class is used to parse command-line input from the user. In general, the command-line arguments are given as individual strings, but each string may contain multiple arguments. You can also use regular expressions to parse the command line. Example: The following example shows a simple command-line processor that creates a new text file, given the name of the file as the first argument and the contents of the file as the second argument. public class CommandLineExample { public static void main(String[] args) { System.out.println("Command line argument:"); CommandLine cmdLine = new CommandLine(new StringReader("-i ")); cmdLine.parseArguments(args); File file = new File("textfile.txt"); FileWriter out = new FileWriter(file); BufferedWriter bw = new BufferedWriter(out); BufferedReader in = new BufferedReader(new FileReader(file)); String line = ""; while((line = in.readLine())!= null) { bw.write(line); } in.close(); bw.close(); System.out.println("Finished writing to textfile."); } } CommandLine: parses the given command line arguments. Parameter: a parameter that may be used to interpret the command line. Description: Creates a CommandLine object. The parameters are specified as strings. Arguments: input - a StringReader object that reads the input from the command line. Parameters: argument - the name of the first command line argument. stringReader - a StringReader that reads the input from the command line. Description: Creates a new CommandLine object with the given parameters. The parameters are specified as strings. Example: This example parses the following command line and writes the output to a text file. public class ParseExample { public static void main(String[] args) { System.out.println("Command line argument:"); CommandLine cmdLine = new CommandLine("-i"); cmdLine.parseArguments(args); File file = new File("textfile.txt"); FileWriter out = new FileWriter(file); BufferedWriter bw
Before purchase: The P2P platform, including Dropbox, will be integrated, and the host of the computer may be infected by viruses, due to the dynamic nature of the Internet environment. Download the "Dropbox/other" folder on your computer, and enter the correct link to open the P2P platform, or otherwise, it will be difficult to use after the computer is installed. Install "Windows Defender" and "Ad-Aware SE" antivirus software, to ensure that your computer is safe to play. The P2
Fireworks Windows 7 ThemeImage to ASCII converterCommTestTXT2HTML ConverterClip to OneNote Listener