import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
public class CopyPic {
/**
* @param args
* @throws IOException
* @throws IOException
*/
public static void main(String[] args) throws IOException {
copyPic_1();
copyPic_2();
}
public static void copyPic_1() throws IOException {
FileInputStream fis = new FileInputStream("e:\\test\\01.jpg");
FileOutputStream fos = new FileOutputStream("e:\\test\\llh.jpg");
byte[] by = new byte[fis.available()];
fis.read(by);
//??这里为什么我不读进数组也可以呢?
fos.write(by);
fis.close();
fos.close();
}
public static void copyPic_2() throws IOException
{
FileInputStream fis = new FileInputStream("e:\\test\\01.jpg");
FileOutputStream fos = new FileOutputStream("e:\\test\\lla.jpg");
byte[] by = new byte[1024];
int len;//还有这里不赋值也是可以的吧,怎么看视频都要赋值的呢?
while((len = fis.read(by)) != -1)
{
fos.write(by,0,len);
}
fis.close();
fos.close();
}
}
|