FileInputStream fr=null;
FileOutputStream fw=null;
String path = "复制前文件路径";
String path = "复制后文件路径";
try {
fr = new FileInputStream(path);
fw = new FileOutputStream(copyPath);
// 循环读和循环写
byte[] bytes = new byte[1024];
int len;
// fr.read(bytes))里如果不写bytes会有复制10倍问题
while((len = fr.read(bytes)) != -1) {
fw.write(bytes, 0, len);
}
}catch (Exception e){
e.printStackTrace();
} finally {
try {
fr.close();
fw.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
读写mp3文件时,用FileWriter和FileReader会有读取问题,读取失败。原因:FileWriter和FileReader用来读取文本文件。