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. Gracias.
View Tutorial          By: maiki at 2015-03-05 15:20:05

2. why do't you create ActionErrors object like this<
View Tutorial          By: veera reddy at 2011-07-15 12:14:57

3. What a wonderful site for beginners? Now I can pra
View Tutorial          By: Kafedha Rwezaula at 2010-06-03 04:39:59

4. Thanks man it is very very helpfull for me.

View Tutorial          By: qasim azam at 2011-06-15 18:09:35

5. I need a sample example using checkbox in struts.t
View Tutorial          By: Nandhu at 2011-02-25 07:45:39

6. this helps a lot
View Tutorial          By: Ashar at 2010-04-28 04:47:36

7. thank you soo much .. itss realy helpful.... :)
View Tutorial          By: prakriti at 2011-12-03 16:47:11

8. I deploy a project in apache tomcat and backend to
View Tutorial          By: satish at 2010-08-04 05:31:59

9. i can saved when i run the program...
but w

View Tutorial          By: kathleen ashley at 2010-08-02 05:22:46

10. why we use the java in networking and What are the
View Tutorial          By: ali mohammed at 2015-10-11 23:03:40