Hello there! Since being on these forums, I have learned a lot more about Java programming than I have in class. I am only in an intro class, but still, thank you guys! Just wanted to let ya know.
Now for mt problem. We just had a class on creating objects, but i have been having a lot of problems. The following code was similar to what the professor gave us in class, which was used as an example to learn from, not code that was supposed to be compiled directly by copying and pasting. There are a lot of things that i am not getting right. Could you please look at my code and give me some pointers? Or maybe point me into the right direction. Thanks!
Code won't compile of course, and I know these are bad variable names, but what variable names would be good for this? Thanks again in advance! [ October 29, 2004: Message edited by: Sean Magee ]
I think you need a space between the new keyword and the File or FileReader class names. You probably also need to import java.io.* to use the File class and the various reader classes. Apart from that, Java variable names are usually in lowercase and something descriptive that tells the programmer something about the object or primitive being referred to.
You're missing a comparison operator. Your code is:
You need to add a comparison operator:
See the comparison now? The while is reading a line into the line variable and, if it's not equal to null, show the message. Typographical errors are the most common mistakes that cause bugs in programs.
Good luck in your class!
Give a man a fish, he'll eat for one day. Teach a man to fish, he'll drink all your beer.
Cheers, Jeff (SCJP 1.4, SCJD in progress, if you can call that progress...)
Joined: Aug 23, 2004
Don't know if anyone cares, but here is my code completed by me, from the help of you fello Ranchers. Thanks!
I do have one question though, if someone can explain this. (sorry i ask too many questions)
I compiled your code without the java.io.File successfully. However, for readability, it is preferable to use "import java.io.File" rather than "import java.io.*". Here is a recent thread that talks about this topic.