Click here to Skip to main content
15,906,316 members

Comments by Member 14767000 (Top 7 by date)

Member 14767000 17-Dec-20 14:37pm View    
Thank you so much for the help, I've figured out where to put the file and now everything works!
Member 14767000 17-Dec-20 10:36am View    
I put "throws FileNotFoundException" and now it works, thank you! However, both the "input.txt" and "Main.java" are in the same folder so why can't the file be found if I instead put:< File file = new File("input.txt"); >. When I use file.exists() to check if it exists, it returns false in this case. Why can't File find the file?



public static void main(String[] args) throws FileNotFoundException
{
// File file = new File("C:/Users/josep/OneDrive/Documents/java/input.txt/");
File file = new File("input.txt"); //why won't this work?

if( file.exists() )
{
System.out.println("File exists");
}
else
{
System.out.println("Doesn't exist"); //This prints out.
}
//System.out.println(file.getAbsolutePath());
Scanner input = new Scanner(file);

String str = input.nextLine();
System.out.println("Str: " + str);

input.close();

}
Member 14767000 17-Dec-20 10:22am View    
The slash was actually not the issue. I had just put the slash to see if it'd work but it still did not. The issue was that I did not put a try catch block or "throws FileNotFoundException". Thank you for your input!
Member 14767000 17-Dec-20 10:22am View    
Deleted
The slash was actually not the issue. I had just put the slash to see if it'd work but it still did not. The issue was that I did not put a try catch block or "throws FileNotFoundException". Thank you for your input!
Member 14767000 24-Apr-20 17:10pm View    
I tried, but I got a correct solution already. It turns out that doing if(isdigit(...) == true) isn't a good idea and that I am supposed actually just do if((isdigit(...)). Thank you for your responding!