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. The tutorial, it's very easy to be understood

View Tutorial          By: newcomer at 2012-04-25 03:49:35

2. Thanks for the info
View Tutorial          By: info at 2010-01-31 12:17:58

3. Good Explanation.
View Tutorial          By: Ashishkumar Haldar at 2013-01-03 11:47:25

4. This tutorial is really fantastic.It helped me a l
View Tutorial          By: Rakesh Verma at 2008-06-25 13:25:23

5. pls send to me comm.jar file , its not in sun si
View Tutorial          By: sanjeewa at 2010-04-18 23:17:37

6. Highly appreciatable.Excellent Docs.
View Tutorial          By: Debi P Naik at 2010-05-04 05:55:45

7. super example...it very useful for me...
View Tutorial          By: elan at 2011-06-02 07:54:39

8. Hello, Can you please send me the complete code to
View Tutorial          By: koksingh at 2008-01-15 00:22:40

9. I'm having trouble figuring out how to sign my mid
View Tutorial          By: Patrick Somers at 2011-04-04 14:54:45

10. Thanks for the simple tutorial on hashmaps. I am n
View Tutorial          By: ipkwena at 2013-08-19 09:02:49