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



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 wanna to name ,subject and marks of every subjec
View Tutorial          By: raveesh yadav at 2012-10-13 19:56:47

2. how to multiply 2.54*0.7071 using only bitwise ope
View Tutorial          By: vindya at 2012-01-12 07:23:08

3. Program is good and easy to understand
View Tutorial          By: sravs at 2011-05-16 00:45:05

4. please help me how to run this program..
View Tutorial          By: khairie at 2009-12-01 22:43:08

5. does not work.

output:
./num

View Tutorial          By: praveen at 2012-08-30 19:04:20

6. simple and clear , thanks a lot!
View Tutorial          By: Steiner at 2012-01-29 19:44:57

7. Thank you sir.
View Tutorial          By: Balan at 2008-09-02 22:16:56

8. Check a cool file reader
View Tutorial          By: John at 2010-09-13 01:38:21

9. its easy to understand the complete history of jav
View Tutorial          By: Arun Tony at 2011-04-10 07:12:04

10. Hi

I want the java code for i

View Tutorial          By: Deepak at 2015-07-29 15:07:09