package assignment;
import java.io.*;
public class AddJava{
public static void main()
{
int num1,num2,sum;
BufferedReader stdin=new BufferedReader(new InputStreamReader(System.in));
try
{
System.out.println("enter first digit");
num1=Integer.parseInt(stdin.readLine());
System.out.println("enter second digit");
num2=Integer.parseInt(stdin.readLine());
sum=num1+num2;
System.out.println(sum);
}
catch(IOException e)
{
System.out.println("input error"+e);
}
}
}
package assignment;
import javax.tools.*;
import java.io.*;
import java.lang.reflect.Method;
import java.net.*;
import java.util.*;
public class JavaApp
{
public static void main(String[] args)throws Exception
{
JavaCompiler jc = ToolProvider.getSystemJavaCompiler();
StandardJavaFileManager sjfm = jc.getStandardFileManager(null, null, null);
File javaFile =new File("C://projectmt//workspace//mtassignment//assignment//AddJava.java");
File[] javaFile1=new File[1];
javaFile1[0]=javaFile;
Iterable fileObjects = sjfm.getJavaFileObjects(javaFile1);
String[] options = new String[]{"-d", "C://projectmt//workspace//mtassignment"};
jc.getTask(null, null, null, Arrays.asList(options), null, fileObjects).call();
try
{
sjfm.close();
}
catch (IOException e)
{
System.out.println("error closing file manager"+e);
}
System.out.println("Class has been successfully compiled");
URL[] urls = new URL[]{new URL("File://C://projectmt//workspace//mtassignment//")};
URLClassLoader ucl = new URLClassLoader(urls);
Class clazz = ucl.loadClass("assignment.AddJava");
System.out.println("Class has been successfully loaded");
Method method = clazz.getDeclaredMethod("main", null);
Object object = clazz.newInstance();
new threadApp();
method.invoke(object,null);
}
}
package assignment;
import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.lang.Runnable.*;
import java.util.StringTokenizer;
public class threadApp implements Runnable{
threadApp()
{
Thread t;
t=new Thread(this,"new thread");
t.start();
}
public void run()
{
try
{
String testNum1,testNum2;
int testSum;
BufferedReader in=new BufferedReader(new FileReader("C://projectmt//workspace//mtassignment//assignment//test.txt"));
String indata=in.readLine();
StringTokenizer tokeniser=new StringTokenizer(indata,"|");
while(tokeniser.hasMoreTokens())
{
testNum1=tokeniser.nextToken();
testNum2=tokeniser.nextToken();
testSum=Integer.parseInt(tokeniser.nextToken());
Thread.sleep(2000);
System.out.println(testNum1);
System.out.println();
Thread.sleep(5000);
System.out.println(testNum2);
}
}
catch(InterruptedException e)
{
System.out.println("Child interrupted");
}
catch(FileNotFoundException e)
{
System.out.println("File not found");
}
catch(IOException e)
{
System.out.println("input error"+e);
}
}
}
i'm using JavaApp to compile load and execute AddJava.
test.txt is a file that contaings the various test case input against which AddJava is to be run.AddJava takes console input.Now i'm having trouble to send the contents of test.txt into the console input of AddJava.i've tried multithreading,in order to use the console output of 1 program as the console input for another,but still no luck.If anybody could help me out here,i would appreciate a lot.
thanks in advance.