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. thanks a lot............
View Tutorial          By: mks at 2013-01-03 06:50:05

2. i added respective code to the Manifest in every c
View Tutorial          By: niko at 2013-04-19 18:23:41

3. HI . i got the following exception while start up
View Tutorial          By: Ramesh at 2011-02-01 00:14:14

4. Puedes enviarme ese codigo, ando embolatado
View Tutorial          By: Wilson at 2011-10-26 22:45:38

5. Hi lolz,
In order for this code to work, yo

View Tutorial          By: Vijay at 2008-12-10 19:22:04

6. can any body explain me how to execute the program
View Tutorial          By: nikhil at 2009-06-04 23:56:11

7. thanks for your explanation, but for desired outpu
View Tutorial          By: bismillah at 2010-09-02 10:16:09

8. Very good explanation . I was very confuse but rea
View Tutorial          By: Shahabaj at 2010-08-10 08:58:39

9. Hi, I need the complete working code for sending a
View Tutorial          By: Balaji Srikaanth at 2007-03-10 01:22:35

10. hi,
can you send me more examples regarding

View Tutorial          By: Ram M at 2015-10-05 06:32:27