import java.net.*;
import java.io.*;
class khd
{
public static void main(String[] args) throws Exception
{
Socket s=new Socket("127.0.0.1",4788);
FileInputStream p=new FileInputStream(new File("d://001.jpg"));
OutputStream xie=s.getOutputStream();
byte lin[]=new byte[1024];
int le=0;
while ((le=p.read(lin))!=-1)
{
xie.write(lin,0,le);
}
s.shutdownOutput();
BufferedReader f=new BufferedReader(new InputStreamReader(s.getInputStream()));
System.out.println(f.readLine());
p.close();
s.close();
}
}
class fwq
{
public static void main(String[] args) throws Exception
{
ServerSocket s=new ServerSocket(4788);
Socket k=s.accept();
FileOutputStream xie=new FileOutputStream(new File("copy.jpg"));
InputStream dq=k.getInputStream();
byte lin[]=new byte[1024];
int le=0;
while ((le=dq.read(lin))!=-1)
{
xie.write(lin,0,le);
}
BufferedWriter f=new BufferedWriter(new OutputStreamWriter(k.getOutputStream()));
f.write("上传成功!");
f.newLine();
f.flush();
k.close();
s.close();
}
}
|
|