String path = "C:" + File.separator + "testFolder" + File.separator + "one.txt";
Scanner sc = new Scanner(path);
while (sc.hasNextLine()) {
System.out.println(sc.nextLine());//prints C:\testFolder\one.txt once
}
Edit: My file one.txt contains 3 lines of text I would like java to loop through all the lines and print me those three lines. But I only get "C:\testFolder\one.txt" printed on the console once only with this code.
This seems to happen only when i am using file.separator for the file path, if I use C:\\testFolder\\one.txt
or C:/testFolder/one.txt
for file path it loops through the file and reads the file with all three lines. What can be done to read the whole file with the File.separator
?