Page 1 of 1

Info about PathMatcher

Posted: Wed Aug 14, 2013 5:12 am
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.

Re: Info about PathMatcher

Posted: Sun Aug 18, 2013 3:10 am
by The_Nick
I had missed a ")" when declaring the pattern with getPathMatcher(..);
Without that works fine.

The_Nick.