File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes File IO Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "File IO" Watch "File IO" New topic
Author

File IO

Nevris
Greenhorn

Joined: Feb 09, 2000
Posts: 14
How can I read in data from a data file and implement methods that are called in the data file?
IE)

would be a line in the data file, and it would call a method in the program that performed merge sort 20 times
[This message has been edited by Nevris (edited April 19, 2000).]
paul wheaton
Trailboss

Joined: Dec 14, 1998
Posts: 20729
    ∞

Are you talking about making your own programming language?


permaculture Wood Burning Stoves 2.0 - 4-DVD set
Nevris
Greenhorn

Joined: Feb 09, 2000
Posts: 14
Nope, that's not what I'm talking about.
What I am talking about is ...
say I read in a line of input from a file, and that line said "PrintInOrder" for example .. then that would trigger something in the java program that would print out a tree that I had created ... and it would print it out using the print in order method of binary search trees ... but i have no clue how to do this .. so that's my question ... how would i do that?
Jesper Ottosson
Ranch Hand

Joined: Mar 21, 2000
Posts: 51
just use a FileInputStream to read in the lines, then compare them to the method names in a giant if-elseif statement, and call the proper methods inside this. I don't think there's an easy "magic" way of doing it, you have to do one if per method... well perhaps if you look through the reflection api (java.reflect), you may find something... the stuff there sure is magic.
Tim Reid
Greenhorn

Joined: Apr 20, 2000
Posts: 3
There is a recent discussion of this issue along with examples using java reflection at the following:
http://forum.java.sun.com/forum?13@@.787c29c0/4
John Bateman
Ranch Hand

Joined: Mar 09, 2000
Posts: 320
How about implementing an XML Document.
The DTD could have a tag called "MethodCaller" and then another tag with a bunch of text. You can then use reflection (as mentioned in previous mail), or some sort of custom XML parser, to analyze the DTD/XML doc and run the methods you need.
The problem is that you now have to make sure that the person creating the DTD/XML documents MUST know all about your classes.
I suggest XML here because if you DTD doesn't change and everyone writing these 'text/dat' files follows the dtd (which they have to) then you can be assured that the text/dat files can be correctly read by your program.

SOURCE CODE should be SURROUNDED by "code" tags.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: File IO