Comment on Tutorial - Write to a file in Java - Sample Program By Dorris



Comment Added by : sa

Comment Added at : 2012-08-02 07:09:30

Comment on Tutorial : Write to a file in Java - Sample Program By Dorris
import java.io.File;
import java.util.Scanner;

public class FileExists {
public static void main(String[] s) {
Scanner scanner = new Scanner(System.in);
System.out.print("Enter the url of a file: ");
System.out.flush();
String filename = scanner.nextLine();
File file = new File(filename);
if(file.exists()){System.out.println("exists");}
else{System.out.println("not exists");}
}
}


output1:
Enter the url of a file: C:\Users\298564\Desktop\sa.txt
exists

output2:
Enter the url of a file: C:\Users\298564\Desktop\asdfs.txt
not exists


View Tutorial



Subscribe to Tutorials

Related Tutorials

Program using concept of byte long short and int in java

Update contents of a file within a jar file

Tomcat and httpd configured in port 8080 and 80

Java File

Java String

Count number of vowels, consonants and digits in a String in Java

Reverse a number in Java

Student marks calculation program in Java

Handling Fractions in Java

Calculate gross salary in Java

Calculate average sale of the week in Java

Vector in Java - Sample Program

MultiLevel Inheritance sample in Java

Multiple Inheritance sample in Java

Java program using Method Overriding

Archived Comments

1. Thanks, very helpful. Worked perfectly.
View Tutorial          By: Bob Knob at 2011-07-27 18:22:18

2. Exception in thread "Thread-0" java.lang
View Tutorial          By: Ghulam Murtaza at 2012-12-12 06:43:58

3. thanks for your tutorial, but how to us it?

View Tutorial          By: Desman Gea at 2014-07-18 16:54:41

4. please give me more information
View Tutorial          By: nandhini at 2012-09-22 03:49:11

5. HI everyone,
I want to select par

View Tutorial          By: aarthi.s at 2011-09-06 10:09:16

6. Hi

Where puts this code in ror app

View Tutorial          By: martin at 2013-01-31 08:51:12

7. Very good explanation along with the example. Can
View Tutorial          By: Divya at 2010-09-21 03:05:10

8. Plz help me......its urgent
i need a code

View Tutorial          By: Nisha at 2010-03-22 00:38:42

9. why 27's example is prone to a deadlock ? when pro
View Tutorial          By: kaka at 2011-08-14 00:59:41

10. I agree with BHAGYALAXMI. I faced the same problem
View Tutorial          By: Alok at 2010-01-10 12:03:37