Winsockserver.SendData "sample_image.gif" & Chr(10) mg_filename = "e:\sample_image.gif" da = FileLen(mg_filename) If da = vbNullString Then Exit Sub End IfOpen mg_filename For Binary As #1For i = 0 To da \ 4096 If da < 4096 Then ReDim myfile(1 To da) As Byte Else ReDim myfile(1 To 4096) As Byte da = da - 4096 End If Get #1, i * 4096 + 1, myfile Winsockserver.SendData myfile 'Winsockserver.SendData Chr(10) For j = 1 To 5000 DoEvents Next jNext i
Close #1
那用java怎么实现呀?用什么来读数据流呢?
你的java是如何读数据的呢?满足什么条件才不读取数据呢?
import java.net.*; import java.io.*; import java.util.*;public class sink { public static void main(String[] args) throws IOException { String mg_filename=new String(); Socket client = new Socket("makegame", 8888); System.out.println("Connect ..."); System.out.println(new Date()); BufferedReader mg_filein=new BufferedReader(new InputStreamReader(client.getInputStream())); System.out.println("Reading ..."); mg_filename=mg_filein.readLine(); System.out.println(mg_filename+":"+Integer.toString(mg_filename.length())); BufferedOutputStream out = new BufferedOutputStream(new FileOutputStream(mg_filename),4096); BufferedInputStream in = new BufferedInputStream(client.getInputStream(),4096); byte[] c = new byte[4096]; int count = in.read(c); while (count != -1) { out.write(c,0,count); count = in.read(c); } System.out.println("Reading down."); System.out.println(new Date()); in.close(); out.close(); client.close(); System.out.println("Closed."); }}
[email protected]
mg_filename = "e:\sample_image.gif"
da = FileLen(mg_filename)
If da = vbNullString Then
Exit Sub
End IfOpen mg_filename For Binary As #1For i = 0 To da \ 4096
If da < 4096 Then
ReDim myfile(1 To da) As Byte
Else
ReDim myfile(1 To 4096) As Byte
da = da - 4096
End If Get #1, i * 4096 + 1, myfile Winsockserver.SendData myfile
'Winsockserver.SendData Chr(10)
For j = 1 To 5000
DoEvents
Next jNext i
Close #1
import java.io.*;
import java.util.*;public class sink {
public static void main(String[] args) throws IOException
{
String mg_filename=new String(); Socket client = new Socket("makegame", 8888);
System.out.println("Connect ...");
System.out.println(new Date());
BufferedReader mg_filein=new BufferedReader(new InputStreamReader(client.getInputStream())); System.out.println("Reading ..."); mg_filename=mg_filein.readLine();
System.out.println(mg_filename+":"+Integer.toString(mg_filename.length())); BufferedOutputStream out = new BufferedOutputStream(new FileOutputStream(mg_filename),4096);
BufferedInputStream in = new BufferedInputStream(client.getInputStream(),4096);
byte[] c = new byte[4096]; int count = in.read(c);
while (count != -1)
{
out.write(c,0,count);
count = in.read(c);
}
System.out.println("Reading down.");
System.out.println(new Date());
in.close();
out.close();
client.close();
System.out.println("Closed.");
}}
while (count != -1)
{
out.write(c,0,count);
count = in.read(c);
}
就不会往下执行了,因为in.read(c)是阻塞的。