Computer Science Canada Getting file name using Scanner? |
Author: | Sevenheartz [ Sun Mar 01, 2009 4:05 pm ] | ||
Post subject: | Getting file name using Scanner? | ||
I've used Scanner in order to import a file and go through it
|
Author: | wtd [ Mon Mar 02, 2009 1:16 pm ] |
Post subject: | RE:Getting file name using Scanner? |
No. The Scanner class' constructor takes a Readable object and keeps track of it internally, but does not expose it via a method. |
Author: | DemonWasp [ Mon Mar 02, 2009 1:48 pm ] |
Post subject: | RE:Getting file name using Scanner? |
You can find documentation on all available methods of the core Java API here: http://java.sun.com/javase/6/docs/api/ You'll find that wtd is right; Scanner is a wrapper around any readable object (which may not necessarily have a file name associated with it - you can make a Scanner that reads along a String, for example); it does not expose either the wrapped object or any of its properties directly. |
Author: | wtd [ Mon Mar 02, 2009 1:53 pm ] |
Post subject: | Re: RE:Getting file name using Scanner? |
DemonWasp @ Tue Mar 03, 2009 2:48 am wrote: You'll find that wtd is right
You sound surprised. ![]() |
Author: | Sevenheartz [ Mon Mar 02, 2009 3:16 pm ] |
Post subject: | Re: RE:Getting file name using Scanner? |
wtd @ Mon Mar 02, 2009 1:16 pm wrote: No. The Scanner class' constructor takes a Readable object and keeps track of it internally, but does not expose it via a method.
DemonWasp @ Mon Mar 02, 2009 1:48 pm wrote: You can find documentation on all available methods of the core Java API here: http://java.sun.com/javase/6/docs/api/
You'll find that wtd is right; Scanner is a wrapper around any readable object (which may not necessarily have a file name associated with it - you can make a Scanner that reads along a String, for example); it does not expose either the wrapped object or any of its properties directly. Hmm, I guessed as much. In that case, may I ask how you all would obtain the file's name and output it? |
Author: | DemonWasp [ Mon Mar 02, 2009 3:24 pm ] |
Post subject: | RE:Getting file name using Scanner? |
Store it in another variable - either store the file name as a String, or else store the File object. Edit: wtd, the surprise comes more from reading much of your epic rant against Java, then discovering that you're quite well-versed in it. |
Author: | wtd [ Mon Mar 02, 2009 3:46 pm ] |
Post subject: | Re: RE:Getting file name using Scanner? |
DemonWasp @ Tue Mar 03, 2009 4:24 am wrote: Store it in another variable - either store the file name as a String, or else store the File object.
Edit: wtd, the surprise comes more from reading much of your epic rant against Java, then discovering that you're quite well-versed in it. My hatred comes from familiarity. ![]() |
Author: | DemonWasp [ Mon Mar 02, 2009 4:08 pm ] |
Post subject: | Re: RE:Getting file name using Scanner? |
wtd @ Mon Mar 02, 2009 3:46 pm wrote: My hatred comes from familiarity.
![]() Funny, I get the same feeling about C++ - after using it for a while, it just looks like a collection of design errors and clever traps designed to snare the unwary. But, we're side-tracking this thread. The answer to the original question is this: - You can't retrieve the file name from a Scanner. Scanners do not necessarily scan files. - You can keep track of the opened file separately if you're in a context where you happen to know that the Scanner IS actually scanning a file. Do this with a String. |
Author: | Sevenheartz [ Mon Mar 02, 2009 7:02 pm ] |
Post subject: | Re: RE:Getting file name using Scanner? |
DemonWasp @ Mon Mar 02, 2009 4:08 pm wrote: wtd @ Mon Mar 02, 2009 3:46 pm wrote: My hatred comes from familiarity.
![]() Funny, I get the same feeling about C++ - after using it for a while, it just looks like a collection of design errors and clever traps designed to snare the unwary. But, we're side-tracking this thread. The answer to the original question is this: - You can't retrieve the file name from a Scanner. Scanners do not necessarily scan files. - You can keep track of the opened file separately if you're in a context where you happen to know that the Scanner IS actually scanning a file. Do this with a String. Alright, I got it. Thanks for the help you two! |
Author: | wtd [ Mon Mar 02, 2009 7:11 pm ] |
Post subject: | Re: RE:Getting file name using Scanner? |
DemonWasp @ Tue Mar 03, 2009 5:08 am wrote: - You can't retrieve the file name from a Scanner. Scanners do not necessarily scan files.
THEORY WARNING! This is what we call "polymorphism" in action. |