你的思路很对,直接写就行了,不要忘了Exception:byte[] b=new byte[10240];
byte[] a=new byte[....];
InputStream is=new FileInputStream("input.file");
OutputStream os=new FileOutputStream("output.file");int size;
do{
size=is.read(b);
...
数据加密之后b_>a
...
os.write(a);
}while(size!=-1);
is.close();
os.close();
byte[] a=new byte[....];
InputStream is=new FileInputStream("input.file");
OutputStream os=new FileOutputStream("output.file");int size;
do{
size=is.read(b);
...
数据加密之后b_>a
...
os.write(a);
}while(size!=-1);
is.close();
os.close();
不过java应该有随机操作文件的类吧!
用随机操作文件的类打开文件后,
定位文件块,传给处理方法就行了。
(建议使用处理线程)先up一下!下午帮楼主查查javadoc!good luck
byte[] a=new byte[....];
InputStream is=new FileInputStream("input.file");
OutputStream os=new FileOutputStream("output.file");int size;
do{
size=is.read(b);
...
数据加密之后b_>a
...
os.write(a);
}while(size!=-1);
is.close();
os.close();我用这个方法读取一个文件,然后直接写到另一个文件。我用的是一个.zip文件,正常的话新文件和源文件应该完全相同,可是新文件与源文件大小不同,新文件解压得时候会出现错误
请注意size,你不会自己处理一下吗?os.write(a,0,size);//write(byte[] b, int off, int len)
byte[] bytIn = new byte[10240];
String fileOut = fileIn.getPath() + ".tdes";
OutputStream fos = new FileOutputStream(fileOut);
int size;
do{ size = fis.read(bytIn);
fos.write(bytIn,0,size);
}while(size!=-1);
fos.close();
fis.close();
fos.write(bytIn,0,size);
}while(size!=-1); 忘了,size!=-1的判断应该提前,在write前应该按标准写法:
while((size=fis.read(bytin))!=-1){
fos.write(bytin,0,size);
}没有ide,就是会写错,只有有ide,我才会改错