我已经编写了一个代码来在两个客户端和服务器之间发送和接收文件,但我希望这两个功能都在一个程序中。所以我写了一个包含发送和接收函数的单独类。我已经声明了两个变量sendFilePath
和receiveFilePath
. 我调用了该方法
transfer(String sendFileName, String receiveFileName)
并为这些变量赋值,但它显示为空。
我怎样才能做到这一点?
实际上我想发送sendFilePath
到rf.receive();
和方法如何完成receiveFilePath
?sf.send();
class TransferFile implements Runnable
{
Thread thread;
String sendFilePath, receiveFilePath;
SendFile sf = new SendFile();
ReceiveFile rf = new ReceiveFile();
public void TransferFileCreateThread(String name)
{
thread = new Thread(this,name);
thread.start();
}
public void run()
{
rf.receive(sendFilePath);
sf.send(receiveFilePath);
}
public void transfer(String sendFileName, String receiveFileName)
{
try
{
sendFilePath = sendFileName;
receiveFilePath = receiveFileName;
TransferFile t1 = new TransferFile();
TransferFile t2 = new TransferFile();
t1.TransferFileCreateThread(sendFilePath);
t2.TransferFileCreateThread(receiveFilePath);
}
catch(Exception e)
{
}
}
}