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. i think this ist perfectly fine :) if you don't kn
View Tutorial          By: julian at 2011-03-07 05:54:08

2. wow........thanks a lot :)
View Tutorial          By: shiva at 2015-08-11 07:47:08

3. thanks for this tutorial
View Tutorial          By: d3ptzz at 2009-08-03 23:38:57

4. This site is an Excellent Choice for lerners.Thank
View Tutorial          By: Sravanthi at 2011-06-28 06:20:35

5. I am geting following exception
javax.comm

View Tutorial          By: Raviteja at 2014-06-23 12:46:06

6. i want to open pdf file from sd card and i dont wa
View Tutorial          By: Karan Mavadhiya at 2013-01-30 12:02:30

7. method overloading possible across classes????
View Tutorial          By: Rohit at 2011-01-26 20:23:02

8. i like this site.good explanation,but it is good f
View Tutorial          By: mamata at 2010-08-16 05:22:53

9. hi please help me . i want the full code to send t
View Tutorial          By: Prashant at 2008-04-16 06:08:23

10. sir there is no startapp(),destroyapp() and pause
View Tutorial          By: Sathish at 2012-08-20 08:49:33