I am reading a book related to the OCP exam. I was studying about Path and URI and noticed something strange. Here is my code:
URI u1 = new URI("file://C:/Brother/DrvLangChg/LangList.ini");
Path f = Paths.get("C:/Brother/DrvLangChg/LangList.ini");
Path p1 = Paths.get(u1);
for(int i = 0; i < p1.getNameCount(); i++) {
System.out.print(p1.getName(i) + " ");
}
System.out.println(p1.getRoot());
System.out.println();
for(int i = 0; i < f.getNameCount(); i++) {
System.out.print(f.getName(i)+" ");
}
System.out.println(p1.getRoot());
And this is the output:
DrvLangChg LangList.ini \C\Brother\
Brother DrvLangChg LangList.ini \C\Brother\
What I noticed is that internally Java sets a type "file" when using the URI while the type is null with the String parameter (I am on Windows 10).
I am a little puzzled by this and I would like to learn more about this strange (in my opinion) behavior and what I should watch for if I am using Path.
Edit:Got it, thanks for the comments.