Beginner Ben

Greenhorn
+ Follow
since Jan 12, 2001
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Beginner Ben

Thanks a lot, Morgan. have a great weekend
Ben
Thanks a lot to all you guys. I do appreciate your help.
I still have one more question about the import statement, why not just import.io.* for all?
Thanks again and have a great weekend.
Ben
SOrry for my naive question. What exactly does JLS mean? I heard it a lot. Is it a book? And where can I find it.
thanks a lot
Ben
Thanks for your help. I rewrite my main() as
public static void main(String s[]){
FilePractice fp = new FilePractice();
boolean temp=fp.f1.exists(); //boolean exists()
System.out.println("existance of f1 is "+temp);
}
I guess this is what you mean. However, I still do not understand why my first codes does not work. Why can't I call an File instance constructed in the same class inside my main mehtod?
Ben
Hello everybody,
I am happy to find this place recently and now hoping to get some help from you guys.
I tried to write some codes to help my understanding on File class in IO, but encounter some problems which may arise from somewhere else.
Please see the codes below:
import java.io.File;
public class FilePractice
{
File f1=new File("d:\\java2-certificate");

public static void main(String s[]){
boolean temp=f1.exists(); //boolean exists()
System.out.println("existance of f1 is "+temp);
}
}
error: can not make static reference to nonstatic variable f1 in
FilePractice class.
I got the error message as above. After I move "File f1=new File("d:\\java2-certificate");" into main method, everything is fine. I do not quite understand what it really means. Why can't I code like this? ( I am always weak in anythin static in java).
On the other hand, examples in RHE often use import like
import java.io.File. If import java.io.*; can actually import anything you need in io package, why bother to type File. Will it really slow down the process of the program?
Thanks in advance. I appreciate your help.
Ben