Talk about Java's Args, you may not pay attention to the phenomenon

zhaozj2021-02-16  71

[Problem origin]

I have to be a Class encryption program recently, with my own classload to load EncryptClass, I have to provide a tool to the programmer,

Used to encrypt Class, as a good EXE program, I hope to encrypt Class by command line

Such as: Encryption -Encrypt Class1.class Class2.class

The problem is coming, should I do a way of file wildcard?

Such as: Encryption -Encrypt C? * K? .Class

【Solution】

Good in Google, I search for "FileNameFilter Wildcard Character", found an APPACH organization to be an ORO project, there is

I want something:

Org.Appache.oro.io.globfilenamefilter This can be used, however I found the way Java's way to read Arg during testing.

import java.io.File; import org.apache.oro.io.GlobFilenameFilter; public class Test {public static void main (String [] args) {// Create a filter GlobFilenameFilter filter = new GlobFilenameFilter (args [0]); // Find all the files in the folder matching That filter file cwd = new file ("."); String [] filesfound = cwd.list (filter); // and print them out system.out.println ("Found" FILESFOUND.LENGTH "Files"); for (int i = 0; i

Run: java test * .txt (jdk 1.4.0)

How is the result?

This program prints result is:

Found 1 file

Found file 1.txt

【why】

For the reasons, I added a word in the main function:

System.out.println ("arg [0] =" arg [0]);

turn out:

Arg [0] = 1.txt

This illustrates that Java has performed wildcard when calling parameters, in this example:

Java Test * .txt

with

Java Test 1.txt 2.txt 3.txt is equivalent

Do not believe, you can make him loop print:

For (int J = 0; J

System.out.Println ("arg [" j "] =" arg [j]);

}

Like the result, you are surprised

【in conclusion】

Seeking truth from facts and experiments is the way to test truth, don't want to be of course.

【Related Links】

An foreigner is as confusing as me: here view

Oro project

转载请注明原文地址:https://www.9cbs.com/read-16098.html

New Post(0)