Found a confusing question while learning about file separators
Suppose that the file c:\book\java
exists. Which of the following lines of code creates an object that represents the file? (Choose all that apply.)
1. new File("c:\book\java");
2. new File("c:\\book\\java");
3. new File("c:/book/java");
4. new File("c://book//java");
5. None of the above
the book (assumig a dos based file system) says that
- & 3. are right answer
- is correct because Java requires a backslash to be escaped with another backslash.
- is also correct because Java will convert the slashes to the right one when working with paths..
- Can 4 also be correct by this logic?
- and when i change to mac/linux file system - what should be the answer ? (update: we are only creating a file object - whether it makes sense is not the question here - the question is which of these will finally return the path shown above)