Socket s = new Socket("127.0.0.1",10000);
FileInputStream fis = new FileInputStream(new File("E:\\beautiful.jpg"));
OutputStream os = s.getOutputStream();
byte[] by = new byte[1024];
int len = 0 ;
while((len = fis.read(by))!=-1){
os.write(by,0,len);
}
s.shutdownOutput();
InputStream is = s.getInputStream(); //此处报错 Type mismatch: cannot convert from java.io.InputStream to temp.InputStream 求解 为什么
byte[] byin = new byte[1024];
int num = is.read(byin);
System.out.println(new String(byin,0,num));
fis.close();
s.close();
} 作者: 落木萧萧 时间: 2013-10-9 17:34
导错包了?作者: yting_xmei1129 时间: 2013-10-10 01:36
楼主导错包了,代码发你--->
package snippet;
import java.io.File;
import java.io.FileInputStream;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.Socket;
public class Snippet {
public static void TcpSend()throws Exception{
Socket s = new Socket("127.0.0.1",10000);
FileInputStream fis = new FileInputStream(new File("E:\\beautiful.jpg"));
OutputStream os = s.getOutputStream();
byte[] by = new byte[1024];
int len = 0 ;
while((len = fis.read(by))!=-1){
os.write(by,0,len);
}
s.shutdownOutput();
InputStream is = s.getInputStream(); //此处报错 Type mismatch: cannot convert from java.io.InputStream to temp.InputStream 求解 为什么