The double slash in the file path is required as to create the ’\’ character , another ‘\’ needs to be added to escape it. A program that demonstrates this is given as follows −
import java.io.File; public class Demo { public static void main(String[] args) { File file = new File("C:\\jdk11.0.2\\demo1.txt"); System.out.println(file); } }
The output of the above program is as follows −
C:\jdk11.0.2\demo1.txt
Now let us understand the above program.
The file path of the file is provided with double slash and then it is printed. A code snippet that demonstrates this is given as follows −
File file = new File("C:\\jdk11.0.2\\demo1.txt"); System.out.println(file);