3种文件复制方法,得到3种不同大小的文件?怎么回事?请教大侠!!
复制一个war文件, 大小7k.
第一种方法:4K
public void deployLocalWAR(final String absolutepfad,
final String filename) {
try {
DataInputStream is = new DataInputStream(
new BufferedInputStream(
new FileInputStream(new File(absolutepfad))));
DataOutputStream os = new DataOutputStream(
new BufferedOutputStream(
new FileOutputStream(new File(
"c:\\ " + filename))));
final int n = 1024;
byte[] by = new byte[4*n];
int m;
while ((m = is.read(by)) != -1) {
is.read(by);
os.write(by);
os.flush();
}
is.close();
os.close();
} catch (
IOException e) {
System.err.println(e.getCause());
}
第二种方法:1K
就是把while循环语句改称:while (is.available()> 0) {
is.read(by);
os.write(by);
os.flush();
}
第三种方法,就是7k了
public void deployLocalWAR(final String absolutepfad,
final String filename) {
try {
File war=new File(absolutepfad);
DataInputStream is=null;
DataOutputStream os=null;
byte[] b;
File f=new File( "c:\\ " + filename);
is=new DataInputStream(new FileInputStream(war));
b=new byte[is.available()];
is.read(b);