wood burning stoves*
The moose likes Beginning Java and the fly likes Output of the Program Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Output of the Program" Watch "Output of the Program" New topic
Author

Output of the Program

Karthikeyan Ravindran
Ranch Hand

Joined: Nov 20, 2007
Posts: 32
can anyone tell me the output of the following program..while compling am getting the following errors....

Program
import java.io.*;

class filedemo
{
public static void main(String args[])
{
File f = new File("hai.txt");
System.out.println("File obj gives file name=" +f);
System.out.println("name = " +f.getName());
if(f.exists()==true)
System.out.println("File exists");
else
System.out.println("Does not exists");
}
}


And the output

filedemo.java:7: cannot find symbol
symbol : constructor File(java.lang.String)
location: class File
File f = new File("hai.txt");

^
filedemo.java:9: cannot find symbol
symbol : method getName()
location: class File
System.out.println("name = " +f.getName());
^
filedemo.java:10: cannot find symbol
symbol : method exists()
location: class File
if(f.exists()==true)
^
3 errors
Anubhav Anand
Ranch Hand

Joined: May 18, 2007
Posts: 341

The program is perfectly fine.

It will output
File obj gives file name=hai.txt
name = hai.txt
Does not exists


How are you trying to run it?
Karthikeyan Ravindran
Ranch Hand

Joined: Nov 20, 2007
Posts: 32
Anand I am trying to run this program as i used to do with other program.
i could not find out the error. Is there any special way to run a File program???
Can you help me out??

Anubhav Anand
Ranch Hand

Joined: May 18, 2007
Posts: 341

What I mean is that are you trying to run with some IDE or directly from command prompt.

If running from command prompt make sure that you your classpath or path(depending the way you choose to run) is set properly.
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19684
    
  20

Have you created a class called File that is in the same folder, or some other folder on your classpath?

Because it CAN find a File class, but then doesn't recognize methods and a constructor that are very much part of the java.io.File class. Therefore, it looks like it uses some other class also called File. Since it isn't imported, the only other possibility would be that that class is in the same package - in this case the default package.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Karthikeyan Ravindran
Ranch Hand

Joined: Nov 20, 2007
Posts: 32
Thank you Rob.. Thank you anand. i got the answer
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19684
    
  20

So what was the problem?
Karthikeyan Ravindran
Ranch Hand

Joined: Nov 20, 2007
Posts: 32
i had two JDk and two Jre installed in my computer. i uninstalled and run the program again.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Output of the Program