Hi. I haven't done much in Java, but I'm taking another class in it, so I'll probably be asking questions here a lot. Most of what I've learned has been from Actionscript 3, and my focus there (games ) is different from what I do with Java (assignments ).
Sorry if this question has already been asked, I did search for it but couldn't find it. (Believe me, I would much prefer to be silent.)
Anyway, I was having trouble accessing a textfile from my program, which I had in a package called assignment1 so I could reference it. The text file was in the same directory as the program, and I was trying to access it by name (just a reader with "customer.txt").
After trial and error, I found that it couldn't find customer.txt because the program was in a package. I've found out I don't even need a package, so I've taken that out, and it works. But I want to find out how to access a local file from a program in a package, and what exactly putting a program in a package does that would make it unable to find a file in its own directory.
EDIT: I'm not sure I made sense. So I'll make sure.
I put my program, BankDriver, in a package (and folder directory inside my path) called assignment1. Inside that folder was a textfile called customer.txt. BankDriver tried to access customer.txt (using a reader passed "customer.txt"), but couldn't find it . I took out the line "package assignment1;" (after a long long time) and it worked, so, I guess a program inside a package can't find it's local directory. Basically, how could the program find the local directory and why didn't it work?
Package names should be used for all but small or temporary applications; the things you are doing as beginners' assignments would count as "small". Once you have more than about a dozen .java files, you should use a package structure, but compiling files in packages is more complicated. So you are better off leaving the package names out for the time being.