About Question enthuware.ocpjp.v7.2.1211 :
Moderator: admin
-
- Posts: 8
- Joined: Wed Sep 10, 2014 2:42 am
- Contact:
About Question enthuware.ocpjp.v7.2.1211 :
Hi,
In this link of java doc http://docs.oracle.com/javase/7/docs/ap ... .String%29
I don't understand why "*" has to be escaped in this line:
C:\\* Matches C:\foo and C:\bar on the Windows platform (note that the backslash is escaped; as a string literal in the Java Language the pattern would be "C:\\\\*")
why shouldn't it be C:\* and in java string "C:\\*"?
Thank you
In this link of java doc http://docs.oracle.com/javase/7/docs/ap ... .String%29
I don't understand why "*" has to be escaped in this line:
C:\\* Matches C:\foo and C:\bar on the Windows platform (note that the backslash is escaped; as a string literal in the Java Language the pattern would be "C:\\\\*")
why shouldn't it be C:\* and in java string "C:\\*"?
Thank you
-
- Site Admin
- Posts: 10036
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question enthuware.ocpjp.v7.2.1211 :
You are not trying to escape *. You are trying to escape two backslashes i.e. \\.
If you like our products and services, please help us by posting your review here.
-
- Posts: 8
- Joined: Wed Sep 10, 2014 2:42 am
- Contact:
Re: About Question enthuware.ocpjp.v7.2.1211 :
Thank you for your answer.
OK now why we need two backslashes in this case?
OK now why we need two backslashes in this case?
-
- Site Admin
- Posts: 10036
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question enthuware.ocpjp.v7.2.1211 :
Because you are trying to match c:\foo not c:/foo. So you need to escape \ in the path matcher expression itself. So you get two \ in the expression. When you put it in java code, you need to escape each of them.
This explains more: http://www.jedit.org/users-guide/globs.html
http://mywiki.wooledge.org/glob
This explains more: http://www.jedit.org/users-guide/globs.html
http://mywiki.wooledge.org/glob
If you like our products and services, please help us by posting your review here.
-
- Posts: 10
- Joined: Sat Jan 24, 2015 8:09 am
- Contact:
Re: About Question enthuware.ocpjp.v7.2.1211 :
Why isn't this discussion about the related question?
I don't understand the explanation: "Path objects that we are checking contain the complete path including directories (such as c:\works\pathtest\a.java and not just a.java). Therefore, nothing will match."
Why doesn't it match a.java
*.java would match everything that ends with .java, right?
I don't understand the explanation: "Path objects that we are checking contain the complete path including directories (such as c:\works\pathtest\a.java and not just a.java). Therefore, nothing will match."
Why doesn't it match a.java
*.java would match everything that ends with .java, right?
-
- Site Admin
- Posts: 10036
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question enthuware.ocpjp.v7.2.1211 :
What do you mean? The question is about matching paths.EelcoD wrote:Why isn't this discussion about the related question?
Wrong. The * character matches zero or more characters of a name component without crossing directory boundaries.I don't understand the explanation: "Path objects that we are checking contain the complete path including directories (such as c:\works\pathtest\a.java and not just a.java). Therefore, nothing will match."
Why doesn't it match a.java
*.java would match everything that ends with .java, right?
Please go through this for complete details : http://docs.oracle.com/javase/7/docs/ap ... ng.String)
HTH,
Paul.
If you like our products and services, please help us by posting your review here.
-
- Posts: 10
- Joined: Sat Jan 24, 2015 8:09 am
- Contact:
Re: About Question enthuware.ocpjp.v7.2.1211 :
But a.java resides in the pathtest directory, so you're not crossing any boundaries.
What am I missing?
What am I missing?
-
- Site Admin
- Posts: 10036
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question enthuware.ocpjp.v7.2.1211 :
If you run the program and print each Path given to MyFileChecker by walkFileTree, you will see that the Paths are not relative paths. They all start with c:\works\pathtest. So it doesn't get a.java. It gets c:\works\pathtest\a.java. That is why the match fails.
HTH,
Paul.
HTH,
Paul.
If you like our products and services, please help us by posting your review here.
-
- Posts: 10
- Joined: Sat Jan 24, 2015 8:09 am
- Contact:
Re: About Question enthuware.ocpjp.v7.2.1211 :
So, the *.java will try to match it with c:\ or with works\ ?
-
- Site Admin
- Posts: 10036
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question enthuware.ocpjp.v7.2.1211 :
Not sure what you mean. I would suggest you to run the program and print the value of Path in the check method. Basically, *.java doesn't match c:\works\pathtest\a.java. *.java will only match a.java (which you are not getting in the check method.)EelcoD wrote:So, the *.java will try to match it with c:\ or with works\ ?
If you like our products and services, please help us by posting your review here.
-
- Posts: 10
- Joined: Sat Jan 24, 2015 8:09 am
- Contact:
Re: About Question enthuware.ocpjp.v7.2.1211 :
It's hard for me to explain aparently..
The * doesnt cross boundaries meaning it doesnt check past the first backslash?
The * doesnt cross boundaries meaning it doesnt check past the first backslash?
-
- Site Admin
- Posts: 10036
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question enthuware.ocpjp.v7.2.1211 :
I guess you can say that.
If you like our products and services, please help us by posting your review here.
-
- Posts: 14
- Joined: Sun Dec 06, 2015 2:15 pm
- Contact:
Re: About Question enthuware.ocpjp.v7.2.1211 :
Would "glob:*{.java}" and "glob:*.{java}" match all the java files just as "glob:**.java" would?
Thanks
Thanks
-
- Site Admin
- Posts: 10036
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question enthuware.ocpjp.v7.2.1211 :
What happened when you tried it out?
If you like our products and services, please help us by posting your review here.
-
- Posts: 14
- Joined: Sun Dec 06, 2015 2:15 pm
- Contact:
Re: About Question enthuware.ocpjp.v7.2.1211 :
yeah, they don't...we have to always match against the name of the file, not the whole path if we want one asterisk to work
Who is online
Users browsing this forum: No registered users and 49 guests