public class tcpfasong
{
Socket socket;
BufferedOutputStream os;
tcpfasong() throws SocketException,IOException
{
try{
InputStream in=new DataInputStream(new FileInputStream("C:\\Users\\Administrator\\Desktop\\fasong.jpg"));
socket=new Socket(InetAddress.getByName("localhost"),10000);
os=new BufferedOutputStream(new socket.getOutputStream());
int i;
byte []buf=new byte[60000];
while((i=in.read(buf))!=-1)
{
os.write(buf);
}
}catch(IOException e){System.out.print("1"+e);}
socket.close();
}
public static void main(String[] args) throws Exception {
// TODO Auto-generated method stub
new tcpfasong();
}}
import java.io.DataInputStream;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.InetAddress;
import java.net.Socket;
import java.net.SocketException;public class tcpfasong {
Socket socket;
BufferedOutputStream os; tcpfasong() throws SocketException, IOException {
try {
InputStream in = new DataInputStream(new FileInputStream(
"C:\\Users\\Administrator\\Desktop\\fasong.jpg"));
socket = new Socket(InetAddress.getByName("localhost"), 10000);
os = new BufferedOutputStream(socket.getOutputStream());
int i;
byte[] buf = new byte[60000];
while ((i = in.read(buf)) != -1) {
os.write(buf);
}
} catch (IOException e) {
System.out.print("1" + e);
}
socket.close();
} public static void main(String[] args) throws Exception { // TODO
new tcpfasong();
}
}
这句有问题new socket.getOutputStream();多了一个new