0

text file confusion

import java.io.File; public class MyClass { public static void main(String[ ] args) { File x = new File("C:\\Users\\Cameron\\Documents\\textFile.txt"); if(x.exists()) { System.out.println(x.getName() + "exists!"); } else { System.out.println("The file does not exist"); } } } //Why does this always output "The file does not exist"? I have tried many different text files and I can't get it to work. I think I'm doing something wrong with entering the text file. Please help

18th Oct 2017, 1:30 AM
Cameron
1 Odpowiedź
+ 5
Your code works for me. If you gave your full name on install, try that or: check for a long name using the short 8.3 syntax (dir /x shows these): C:\\Users\\Camero~1\\Documents\\textFile.txt Try your full name with a space too. also check for double extension: C:\\Users\\Cameron\\Documents\\textFile.txt.txt Finally, File.listfiles(): https://stackoverflow.com/a/5694398
18th Oct 2017, 4:35 AM
Kirk Schafer
Kirk Schafer - avatar