读取图片演示字节流 使用字节流读取文本可能出现乱码问题(不在内存读,直接复制到另一个文件,不存在问题)
一、字节流进行读入读出复制
public class ByteStreamCopyUtils {
public static void main(String[] args) {
copy("","");
}
public static void copy(String scrPath,String descPath){
FileInputStream fileInputStream = null;
FileOutputStream fileOutputStream = null;
try {
// 1、文件
File scrFile = new File(scrPath);
File descFile = new File(descPath);
// 2、流
fileInputStream = new FileInputStream(scrFile);
fileOutputStream = new FileOutputStream(descFile);
// 3、复制
byte[] data = new byte[1024];
int len;
while ( ( len = fileInputStream.read(data) ) != -1 ){
fileOutputStream.write(data,0,len);
}
}catch (Exception e){
e.printStackTrace();
}finally {
if(null != fileInputStream){
try {
fileInputStream.close();
} catch (IOException e) {
e.printStackTrace();
}
}
if(null != fileOutputStream){
try {
fileOutputStream.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
}