copy picture 和 通过字节流的缓冲区完成复制201

2016-10-10  本文已影响15人  大虾咪

//copy picture

FileInputStream fis = null;

FileOutputStream fos = null;

try {

fis = new FileInputStream("/Users/denmeiho/Desktop/笔记/未命名文件.png");

fos = new FileOutputStream("/Users/denmeiho/Desktop/笔记/未命名文件1.png");

byte[] buf = new byte[1024*1024];

int len = 0;

try {

while ((len = fis.read(buf))!=-1) {

fos.write(buf, 0, len);

}

} catch (IOException e) {

// TODO Auto-generated catch block

e.printStackTrace();

}

} catch (FileNotFoundException e) {

// TODO Auto-generated catch block

e.printStackTrace();

}finally {

try {

fis.close();

fos.close();

} catch (IOException e) {

// TODO Auto-generated catch block

e.printStackTrace();

}

}

//////////////////////////////

//通过字节流的缓冲区完成复制

static void copyMp3(){

BufferedInputStream bis = null;

BufferedOutputStream bos = null;

FileInputStream fis = null;

FileOutputStream fos = null;

try {

fis = new FileInputStream("/Users/denmeiho/Desktop/其他/CSII项目/ShanDongNongxin0905喜子姐/JSZXYH/SDK/face_SDK/audio/动作不规范.mp3");

bis = new BufferedInputStream(fis);

fos = new FileOutputStream("/Users/denmeiho/Desktop/xx.mp3");

bos = new BufferedOutputStream(fos);

byte[] buf = new byte[1024];

int by = 0;

try {

while((by = bis.read())!=-1){

bos.write(by);

}

} catch (IOException e) {

// TODO Auto-generated catch block

e.printStackTrace();

}

} catch (FileNotFoundException e) {

// TODO Auto-generated catch block

e.printStackTrace();

}finally {

bis.close();

bos.close();

}

}

上一篇下一篇

猜你喜欢

热点阅读