Computer Science Canada Reading one text file as part of an array? |
Author: | soapp [ Wed Jan 13, 2010 6:41 pm ] |
Post subject: | Reading one text file as part of an array? |
Hello, I was wondering if it's possible to use one single method that includes statements for reading a text file, and use it to read different text files when invoked from other different methods, or somehow make the text files as parts of an array. This would certainly help cut down on the number of lines used in my program :p Thanks in advance. |
Author: | Ktomislav [ Wed Jan 13, 2010 6:53 pm ] |
Post subject: | Re: Reading one text file as part of an array? |
It is nothing you should be asking help for.. Just simply google it or let me google it for you. Here: http://lmgtfy.com/?q=read+file+java |
Author: | DemonWasp [ Wed Jan 13, 2010 10:38 pm ] | ||
Post subject: | RE:Reading one text file as part of an array? | ||
Yes. What you're looking for, contrary to Ktomislav's post, are arguments. No, not that kind. What you want to do is ask this method to "read file X", where X is the name of whatever file you want to read. This is done as follows in Java (very similar in many languages):
I won't fill in that method for you, but it should prove simple enough. You've hit on a key part of good programming: using methods with arguments is an excellent way to reduce the amount of code in the program (almost universally a good thing). |