you might want to have a look at java properties file.
is that what you need?
http://www.exampledepot.co
http://java.sun.com/j2se/1
Main Topics
Browse All TopicsFriends,
i have text file include text as java statement for example first line is : "var1 = 5 ;"
i need from java program code to read this line from the text file and let java program treat it as a statement not as string that give me chance to use var1 later inside the code and so on...
so how can i do it?
i tried some solutions depends on com.sun.util.... but i do not know how and where could i get this package to be work correctly in my pc?
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
you might want to have a look at java properties file.
is that what you need?
http://www.exampledepot.co
http://java.sun.com/j2se/1
You cannot "run" text that you read from a file. For example, you cannot read a text file that contains a statement like "Thread t=new Thread();", and then expect your program to have an object called t of type Thread available for use!
However, you can have a similar effect by creating code structures that define, initialize and use objects dynamically based on what is read from a file.
_______________
Nayer Naguib
nayernaquib: I beg to differ. All you need is an interpreter.
for example, something like: http://tns-www.lcs.mit.edu
HonorGod: I'm afraid an interpreter will not help in this case.
What the author would like to do is the following:
Let the text file code.txt contain the following line of text:
int z=5;
and let the method that reads this text file contain the following code:
void readFile() {
int x=0, y=2;
readAndExecuteFile("code.t
//and runs the Java statements contained in the file
//then the user would like to put here for example x=y*z; and of course would like it to work!
//note that z was defined in the file not in the code!
}
This is not possible, because there is no Java API that will directly execute Java source code at runtime.
_______________
Nayer Naguib
readAndExecuteFile() does not really exist! It's only here to explain what you wanted to do.
As I told you, you can put switch or if statements inside your code to dynamically execute statements depending on the contents of the text file, but you will not be able to directly execute Java code this way.
_______________
Nayer Naguib
Business Accounts
Answer for Membership
by: makerpPosted on 2007-01-02 at 04:20:54ID: 18227125
what you should do is create an interface and then compile an implementation of it at run-time... for example
k.org/)
interface IGetVariable{
public int getValue();
}
then in your code program to that interface rather than a concrete type
so
// use the compiler services to compile the text file
IGetVariable var = new GetVariableImpl();
/* have this in yoru text file */
class GetVariableImpl{
public int getValue(){
return 1;
}
}
of course if you want to be able configure your code in this way rather than have hardcoded classes etc you should consider the spring framework (http://www.springframewor