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. I like ASP.net b'cs it is very easy to understand
View Tutorial          By: prachi at 2010-06-02 06:04:50

2. So simple..Very easy to understand
View Tutorial          By: G.Tejasree at 2011-11-05 11:51:38

3. I really not get your points...
I don't kno

View Tutorial          By: darshit jain at 2014-05-22 09:07:45

4. Artical is good but it is not clearly define that
View Tutorial          By: Rohit Saxena at 2010-09-02 04:00:11

5. @Iqra :

You're welcome. Use sites l

View Tutorial          By: Macho Man at 2012-07-16 08:02:14

6. new Thread(this , "Demo thread") mean
View Tutorial          By: shalini at 2011-12-06 07:29:20

7. Enabling IPV6 at Application Level


View Tutorial          By: i want code , can you send me at 2014-12-28 11:43:35

8. 0
View Tutorial          By: zareen at 2011-08-20 08:27:28

9. It is very help full to me and very simple underst
View Tutorial          By: Reddymalla Babu Sircilla at 2013-02-22 08:28:22

10. This is a simple app and its working good.......
View Tutorial          By: sathish at 2012-04-23 12:16:07