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 for your code
could you send me the

View Tutorial          By: diana jeng at 2009-04-21 03:50:39

2. a very good explanation
View Tutorial          By: ramakrishna at 2012-12-20 04:06:12

3. Actually, 120º *is* 2.0943951023931953
View Tutorial          By: Stephen Blythe at 2012-04-02 03:39:03

4. nice///
View Tutorial          By: MHARLON ALADEN at 2009-08-14 01:00:09

5. PLEASE I WANT A CODE TO BE PUT BEHIND A BUTTON SO
View Tutorial          By: KALUSHA at 2012-07-02 12:32:56

6. very nice notes we are easy to understand this not
View Tutorial          By: maalu at 2013-04-29 07:06:56

7. good......
View Tutorial          By: Sudip Khatiwara at 2010-04-05 22:31:06

8. i get this error too.
: Parent: child proce

View Tutorial          By: Anon at 2009-02-25 08:30:58

9. thank u.....
View Tutorial          By: DiptaRanjan at 2013-02-02 14:56:45

10. Thank you, for simple and useful example.
View Tutorial          By: Dmitriy at 2011-09-04 20:53:53