服务器类:
import java.net.*;
import java.io.*;
public class fileserver {
public static void main(String args []) {
ServerSocket ss=new ServerSocket(2345);
Socket s= ss.accept();
FileInputStream f=new FileInputStream("D:\\FEATURED.txt");
DataOutputStream dout= new DataOutputStream(s.getOutputStream);
byte[] b=new byte[2002];
f.read(b,0,b.length);
dout.write(b,0,b.length);
dout.close();
f.close();
s.close();
}
}
客户端类:
import java.io.*;
import java.net.*;
public class clientserver {
public static void main(String args []) {
Socket s=new Socket("localhost",2345);
FileOutputStream f=new FileOutputStream("E:\\FEATUREDCOPIED.txt");
DataInputStream din= new DataInputStream(s.getInputStream);
byte[] b=new byte[2002];
din.read(b,0,b.length);
f.write(b,0,b.length);
din.close();
f.close();
s.close();
}
}
错误:
请帮助我解决此查询。
注意偏执狂,因为您调用了套接字中的方法:S.GetOutputStream**()**
S.GetInputStream**()**
GetInputStream
和GetOutputStream
是方法,因此必须调用它们,这意味着在它们的名称后面加上括号:S.GetInputStream()
,而不只是S.GetInputStream
。
**更正代码**
服务器类
:
import java.net.*;
import java.io.*;
public class fileserver {
public static void main(String args []) {
try {
ServerSocket ss=new ServerSocket(2345);
Socket s= ss.accept();
FileInputStream f=new FileInputStream("D:\\FEATURED.txt");
DataOutputStream dout= new DataOutputStream(s.getOutputStream());
byte[] b=new byte[2002];
f.read(b,0,b.length);
dout.write(b,0,b.length);
dout.close();
f.close();
s.close();
}
catch(Exception e) {
System.out.println(e.getMessage());
}
}
}
客户端类
:
import java.io.*;
import java.net.*;
import java.lang.*;
public class clientserver {
public static void main(String args []) {
try {
Socket s=new Socket("localhost",2345);
FileOutputStream f=new FileOutputStream("E:\\FEATUREDCOPIEDAGAINs.txt");
DataInputStream din= new DataInputStream(s.getInputStream());
byte[] b=new byte[2002];
din.read(b,0,b.length);
f.write(b,0,b.length);
din.close();
f.close();
s.close();
}
catch(Exception e) {
System.out.println(e.getMessage());
}
}
}