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. If I want to read input from A PDF what should I d
View Tutorial          By: thiru at 2015-08-12 10:57:51

2. concept of static keyword is beautifully explained
View Tutorial          By: jaideep aswal at 2012-04-14 07:21:56

3. works like a charm, though i didn't understand why
View Tutorial          By: primus at 2010-05-19 04:46:18

4. Actually, looking at the code, it looks as somethi
View Tutorial          By: Johnson at 2009-07-28 08:14:38

5. plse can u send me study material or sample questi
View Tutorial          By: sneha at 2015-03-12 09:40:49

6. i'm a student and new to all these HTML and JSP.
View Tutorial          By: sillee at 2009-08-13 03:22:14

7. This isn't entirely correct. A class can be abstra
View Tutorial          By: Jay at 2013-01-30 14:52:15

8. it is 3 days since I searched resolution. It was h
View Tutorial          By: Daniel Costa at 2009-02-25 06:11:27

9. Muy buen ejemplo, aunque como idea general podr&ia
View Tutorial          By: Ligator at 2013-07-26 05:57:47

10. Nice and easy to understand......Thanks for same
View Tutorial          By: vikas at 2011-07-21 07:44:30