易截截图软件、单文件、免安装、纯绿色、仅160KB

关于java的ftp中发送数据和接收数据流的问题

在发送端发送数据:
DataOutputStream outputs=null;
RandomAccessFile sendFile=null;
TelnetOutputStream outs=null;
byte[] b = new byte[2048000];
sendFile=new RandomAccessFile(FtpVariable.RWFileDir+file,"r");
sendFile.seek(0);

//调用上传文件的命令
outs=ftpClient.put(file);

//打开一个输出流
outputs=new DataOutputStream(outs);

while((sendFile.getFilePointer()) <sendFile.length())
{
if(sendFile.length()-sendFile.getFilePointer()>=FtpVariable.dataPacketSize)
    {
sendFile.read(b);//从文件中读出数据
outputs.write(b);//把数据写入输出流
      }
else
    {

sendFile.read(b,0,(int)(sendFile.length()-sendFile.getFilePointer()));
outputs.write(b);
      }
}
在接收端接收数据:
BufferedOutputStream fout=null;
BufferedInputStream din=null;
byte[] buf = new byte[2048000];
fout= new BufferedOutputStream(new FileOutputStream(requestfile));
din = new BufferedInputStream(dsocket.getInputStream());
while((dataLength = din.read(buf,0,buf.length))!=-1)
{
    fout.write(buf,0,dataLength);//写入文件
}


我上传一个6MB的可以正常接收到。但是上传一个5.688mb时,也是接收到6mb,上传1.969mb是,接收到的是2mb,上传3.571mb时,接收到的是4mb。


相关问答:

java如何控制远程Linux重启

我目前在本地的linux上写了一个swing的界面,想通过这个界面来控制其它电脑的linux重启。
我知道用Runtime.getRuntime().exec("shutdown -r");可以控制本机Linux重启,但是怎么控制远程的linux重启呢? ......

Unable to compile class for JSP - Java / Web 开发

<%@page language="java" contentType="text/html;charset=gb2312" import="java.sql.*"%>
<jsp:useBean id="db" class="wang.connectDB"/>
< ......

Java Lucene 中import的问题

我想使用Lucene的代码,发现要import一批文件:
============
import org.apache.lucene.analysis.standard.StandardAnalyzer;

import org.apache.lucene.document.Document;
………………
===== ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号