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



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. hi,
i am safeer, i am try this program in

View Tutorial          By: Safi at 2009-05-22 22:32:04

2. i am new to java programming plz please provide me
View Tutorial          By: Mahammad musthaq at 2012-05-31 14:02:10

3. could you plz tell me how to run this all programs
View Tutorial          By: abhishek at 2010-10-27 00:08:57

4. good example need some more explanation on notify
View Tutorial          By: prashant at 2009-09-08 19:29:54

5. Simple file writer example. .............
<

View Tutorial          By: Chezhian TK at 2010-10-14 21:40:16

6. Good one.. great for beginners..
View Tutorial          By: varun at 2009-09-29 14:18:04

7. I'm working on an intranet site/web application. W
View Tutorial          By: Tony Gingrich at 2011-10-23 21:22:31

8. My friend, How to user ArrayList?
View Tutorial          By: Joao Neto at 2009-06-04 06:28:17

9. nice article...........................
View Tutorial          By: abhijit at 2012-09-24 11:12:46

10. This does not work in following case :
Cli

View Tutorial          By: Amardeep at 2010-01-20 05:59:21