This week's book giveaway is in the OCAJP forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide 1Z0-808 and have Jeanne Boyarsky & Scott Selikoff on-line! See this thread for details.
would any one please tell me that if i want to compile "abc.txt"(in which i have written simple java code) from my java programe(say TestClass) how can i do this??? if someone knows the code please do paste in reply......i am waiting for your response......
Can you store the code in .java file on disk? If so, you can use the javac compiler internally, somewhat like this:
The first parameter is an array of absolute paths of Java source files, the second is where error messages should go, so you might use "new PrintWriter(System.err)" for it. It returns 0 if compilation worked fine, some other int if not.
If it all needs to be in memory then it gets a bit trickier. I described how it can work in this recent article.
Another approach would be to drive javac using Runtime.exec. Which method is best depends on what you intend to do with the resulting class. [ November 10, 2007: Message edited by: Ulf Dittmer ]