public static void backup(File f01,File f02)throws Exception
{
// File f01 = new File(sourcePath);
// File f02 = new File(path);
int temp=0;
FileInputStream fis = new FileInputStream(f01);
FileOutputStream fos = new FileOutputStream(f02);
while(fis.read()!=-1)
{
fos.write(fis.read());
}
再看书上的代码:
public static void backup(File f01,File f02)throws Exception
{
// File f01 = new File(sourcePath);
// File f02 = new File(path);
int temp=0;
FileInputStream fis = new FileInputStream(f01);
FileOutputStream fos = new FileOutputStream(f02);
while((temp=fis.read())!=-1)
{
fos.write(temp);
}
唯一的区别就是write方法的参数,我是直接写了InputStream.read()方法了,书上是通过一个int变量过渡了一下。但是就是这一些过渡,就决定了我保存文件失败了。 既然InputStream.read()返回值是int,为什么不能直接使用,还必须得用个变量过渡一下呀,求各位大侠帮忙解惑一下,3Q。