Answer the question
In order to leave comments, you need to log in
How to create an object of type File?
Hello. There is a problem. Cannot create a File object representing a file on disk. I create a File object for a directory - everything is in order, but when I create a File object for a file - it does not work
Create a File for the directory
public static void main(String[] args) {
// определяем объект для каталога
File dir = new File("C://Java projects");
if(dir.isDirectory()){
System.out.println("это директория"); //работает
}
}
public static void main(String[] args) {
File file=new File("C://Java projects//Films.txt");
if(file.isFile()){
System.out.println("это файл");
}else {
System.out.println("это не файл"); // выводи эту строку
}
}
Answer the question
In order to leave comments, you need to log in
Everything works, I'm sorry. due to inattention, I was stupid for 40 minutes. the file name is Fimls, when it specified an absolute path in the File constructor, the file name was specified by Films.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question