View SourceHide Source/**
* This program is written to save the input parameter of
* a program for future use.
* It uses the library provided by http://www.braju.com/ for printf()
*/
import java.io.PrintStream;
import java.io.FileOutputStream;
import java.io.OutputStream;
/*
* hb16.zip from http://www.braju.com/
* contains set of classes to provide printf() function
*/
import com.braju.format.Format;
import com.braju.format.Parameters;
public class HelloWorld {
static String quote = "Hello World!";
static String code =
"import java.io.PrintStream;" +
"import java.io.FileOutputStream;" +
"import java.io.OutputStream;" +
"import com.braju.format.Format;" +
"import com.braju.format.Parameters;" +
"public class HelloWorld{" +
"static String quote=*%s*;" +
"static String code=*%s*;" +
"public static void main(String args[]) throws Exception {" +
"if(args.length==1)quote = args[0];System.out.println(quote);" +
"OutputStream os = new FileOutputStream(*HelloWorld.java*);" +
"PrintStream ps = new PrintStream(os);" +
"ps.println("+
"Format.sprintf(code.replace('%c', (char)34), "+
"new Parameters(quote).add(code).add((char)42)));" +
"ps.close();" +
"Runtime.getRuntime().exec(*javac -classpath hb16.zip HelloWorld.java*);" +
"}}";
public static void main(String args[]) throws Exception {
if (args.length == 1) quote = args[0];
System.out.println(quote);
OutputStream os = new FileOutputStream("HelloWorld.java");
PrintStream ps = new PrintStream(os);
ps.println(Format.sprintf(code.replace('*', (char) 34),
new Parameters(quote).add(code).add((char) 42)));
ps.close();
Runtime.getRuntime().exec("javac -classpath hb16.zip HelloWorld.java");
}
}
Compile: javac -classpath hb16.zip HelloWorld.java
Execute:
(For Linux) java -cp .:hb16.zip HelloWorld
(For Windows) java -cp .;hb16.zip HelloWorld
Sample:
$ java -cp .:hb16.zip HelloWorld
Hello World!
$ java -cp .:hb16.zip HelloWorld Parameter
Parameter
$ java -cp .:hb16.zip HelloWorld
Parameter
/* Parameter which was the previous input to the program has been saved. */
# posted by Prasad.A : 11:47 PM