xxxxxxxxxx
import os
# Specify the file path
file_path = "path/to/file.txt"
# Check if the file exists
if os.path.exists(file_path):
# Perform desired operations with the file
with open(file_path, 'r') as file:
# Example: Print the contents of the file
print(file.read())
else:
print("File not found!")
xxxxxxxxxx
Generally, just stating the name of file inside the File constructor means
that the file is located in the same directory as the java file. However,
when using IDEs like NetBeans and Eclipse i.e. not the case you have to save
the file in the project folder directory. So I think checking that will solve
your problem.
xxxxxxxxxx
I suspect you are simply having some problem in the actual file name of file.txt,
or you are running in a wrong directory.