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. Bad article ! What about the explanation of Messag
View Tutorial          By: Manish at 2011-05-24 04:44:03

2. how to get only the year like 2012
View Tutorial          By: Iguster at 2012-01-27 22:20:32

3. thanks a lot fo the help offered.
View Tutorial          By: Douglas [email protected] at 2012-10-31 05:37:04

4. import java.io.*;
import java.util.Stack;
View Tutorial          By: jack&jill at 2011-07-26 06:40:32

5. nice examples,but i have one problem in my project
View Tutorial          By: swati at 2015-04-30 10:48:13

6. thankx a lot...i've been trying so hard to learn t
View Tutorial          By: bhuwan at 2009-04-08 23:30:45

7. while i am executing this program i am getting Nul
View Tutorial          By: Seema at 2013-11-26 18:39:15

8. setting on my nokia 7610 on mtn using operamini 4.
View Tutorial          By: DREAD at 2010-06-21 07:40:13

9. Good example.

Leslie V
www.g

View Tutorial          By: Leslie V at 2009-10-14 00:47:06

10. Hi there,
this doesnt work in IE7 or firefo

View Tutorial          By: Gerrard at 2009-10-17 15:19:24