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. Where should the file be placed? How do I know wh
View Tutorial          By: Anon at 2009-07-23 14:08:17

2. if i wanna push the data from my keyboard input, h
View Tutorial          By: andys at 2008-11-09 03:09:32

3. Hi! I'm working on Ubuntu 10.04

At

View Tutorial          By: Rushabh at 2011-01-12 06:22:43

4. The code is really helpfull...
reading or w

View Tutorial          By: sharda at 2010-03-11 03:28:02

5. Thanks sir i am understand to jdbc but who will ru
View Tutorial          By: Ranjeet singh at 2012-05-04 07:40:29

6. nice code....
nice explanation.. thanks

View Tutorial          By: vinitha at 2013-01-10 10:59:02

7. I want to redirect from a servlet page to another
View Tutorial          By: dinesh at 2014-10-20 16:44:26

8. Whne i run this code ,it does not return any ports
View Tutorial          By: amit at 2009-06-10 02:11:13

9. @3
argc simply means the argument count.
View Tutorial          By: CDub at 2010-02-22 09:32:54

10. PROGRAM TO FIND OUT SMALLER NU:-

cl

View Tutorial          By: ishaan gogna at 2012-05-09 19:00:49