
-----------------------------------
soapp
Wed Jan 13, 2010 6:41 pm

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.

-----------------------------------
Ktomislav
Wed Jan 13, 2010 6:53 pm

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

-----------------------------------
DemonWasp
Wed Jan 13, 2010 10:38 pm

RE:Reading one text file as part of an array?
-----------------------------------
Yes. What you're looking for, contrary to Ktomislav's post, are arguments.


public String readFile ( String filename ) {
    // method contents go here
    // whenever you need the name of the file,
    // use the value of the variable 'filename'
}


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).
