• Post Reply Bookmark Topic Watch Topic
  • New Topic

why file's size is different?  RSS feed

 
robertb9527
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hello,nice to meet you!
I want to know why remotefile's size is bigger than localfile's size?
help!Thank you very very much!

two method:

sun.net.ftp.FtpClient ftp;

1. java.io.FileInputStream inFile = new FileInputStream(esPath);
sun.net.TelnetOutputStream outFile = ftp.put(remoteFile);

byte[] bufferDirect = new byte[1024];
while (true) {
int iBy = inFile.read(bufferDirect);
if (iBy < 0)
break;

outFile.write(bufferDirect, 0, iBy);

}

inFile.close();
outFile.close();



2. RandomAccessFile sendFile=new RandomAccessFile(esPath,"r");
sendFile.seek(0);
TelnetOutputStream outs=ftp.put(remoteFile);
DataOutputStream outputs=new DataOutputStream(outs);
int ch;
while(sendFile.getFilePointer()<sendFile.length()){

ch=sendFile.read();
outputs.write(ch);

}

outs.close();sendFile.close();
 
David Harkness
Ranch Hand
Posts: 1646
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can you give us more clues? What are the sizes of the source and destination files (both cases)?

My first guess would be character encodings. With the first method, you're not using an encoding; you're reading/writing raw bytes. With the second, I believe that DataOutputStream will encode the character, though I cannot say for sure.

One thing's for sure, I'd recommend wrapping your network I/O with buffered streams.
 
robertb9527
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thank you,thank you,very thank you!

I do it:
ftp.binary;

that's ok!
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!