Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 Reading one text file as part of an array?
Index -> Programming, Java -> Java Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
soapp




PostPosted: 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.
Sponsor
Sponsor
Sponsor
sponsor
Ktomislav




PostPosted: 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
DemonWasp




PostPosted: 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):

Java:

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).
Display posts from previous:   
   Index -> Programming, Java -> Java Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 3 Posts ]
Jump to:   


Style:  
Search: