I wrote a small program in java to send and receive a data file using two threads. I want the two threads to be in the same class. One thread sends the file and the other thread receives the file. I have wrote the code for it but with few errors. Can you help me figure out the errors in the code. I am a student and a beginner in java, so spare me if there are any silly mistakes.
import java.lang.Thread.*;
import java.io.*;
public class sendques implements Runnable
{
int i=0,c;
static Thread[] t= new Thread[2];
FileInputStream fis=new FileInputStream("ip.jpg");
FileOutputStream fos=new FileOutputStream("output.jpg");
sendques() {
for(i=0;i<2;i++){
t[i]=new Thread(this);
t[i].start();
System.out.println("Threads "+i);
}
}
void run() {
while(true) {
wait();
send();
}
}
void send() {
while((c=fis.read())!=-1) {
t[2].receive(c);
wait();
}
}
void receive(int d) {
while(c!=-1) {
fos.write(d);
t[1].notify();
}
}
public static void main(String arg[]) {
sendques sq=new sendques();
t[1].send();
System.out.println("Quiting..");
}
}