javaio小问题:byte[] buffer = new byte[1444];
//设定一次性能读取的字节数?还是说只能读取一个文件的这么多字节??求解publicvoidcopyFile(StringoldPath,StringnewPath)th...
//设定一次性能读取的字节数?还是说只能读取一个文件的这么多字节??求解
public void copyFile(String oldPath, String newPath) throws IOException {
try {//进行文件的复制
int bytesum = 0;
int byteread = 0;
File oldfile = new File(oldPath);
if (oldfile.exists()) { //文件存在时
inStream = new FileInputStream(oldPath); //读入原文件
System.out.println("文件的大小是:"+inStream.available());
fs = new FileOutputStream(newPath);
byte[] buffer = new byte[1444];//设定一次性能读取的字节数?
while ((byteread = inStream.read(buffer)) != -1) {
bytesum += byteread; //字节数 文件大小
fs.write(buffer, 0, byteread);
}
inStream.close();
fs.close();
}
}catch (Exception e) {
System.out.println("复制文件操作出错");
e.printStackTrace();
}finally{
if(inStream!=null){
inStream.close();
}
if(fs!=null){
fs.close();
}
}
} 展开
public void copyFile(String oldPath, String newPath) throws IOException {
try {//进行文件的复制
int bytesum = 0;
int byteread = 0;
File oldfile = new File(oldPath);
if (oldfile.exists()) { //文件存在时
inStream = new FileInputStream(oldPath); //读入原文件
System.out.println("文件的大小是:"+inStream.available());
fs = new FileOutputStream(newPath);
byte[] buffer = new byte[1444];//设定一次性能读取的字节数?
while ((byteread = inStream.read(buffer)) != -1) {
bytesum += byteread; //字节数 文件大小
fs.write(buffer, 0, byteread);
}
inStream.close();
fs.close();
}
}catch (Exception e) {
System.out.println("复制文件操作出错");
e.printStackTrace();
}finally{
if(inStream!=null){
inStream.close();
}
if(fs!=null){
fs.close();
}
}
} 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询