Info about PathMatcher

Help and support on OCA OCP Java Programmer Certification Questions
1Z0-808, 1Z0-809, 1Z0-815, 1Z0-816, 1Z0-817

Moderator: admin

Post Reply
The_Nick
Posts: 132
Joined: Thu May 16, 2013 9:23 am
Contact:

Info about PathMatcher

Post by The_Nick »

Hi everybody,
I have the following code working within a Files.walkFileTree but not working in a normal main method.

Check this out:

Code: Select all

PathMatcher pm =FileSystems.getDefault().getPathMatcher("glob:*.txt)");
		if(pm.matches(Paths.get("/home/user/Desktop/TryThisOut.txt")))
		{
		System.out.println("true")
		}
		else
		{
			System.out.println("false");
		}
It should prnt out true because the glob is correct and the file do ends with ".txt", the same pattern used with PathMatcher works when used in a Files.walkFileTree method..(visitFile().)

Could you copy and paste the above code in any main method please? (prior to that it's needed changing the path to a valid path pointing to any .txt present in your desktop)
It should print out true, however I get false..

Thanks in advance.


The_Nick.

The_Nick
Posts: 132
Joined: Thu May 16, 2013 9:23 am
Contact:

Re: Info about PathMatcher

Post by The_Nick »

I had missed a ")" when declaring the pattern with getPathMatcher(..);
Without that works fine.

The_Nick.

Post Reply

Who is online

Users browsing this forum: No registered users and 11 guests