package package1;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
public class CopyFile {
public byte[] getFile() throws IOException {
FileInputStream fileInputStream = null;
try {
fileInputStream = new FileInputStream("D:\\aaa.log");
byte[] result = new byte[fileInputStream.available()];
fileInputStream.read(result);
return result;
} catch (Exception e) {
e.printStackTrace();
} finally {
if (fileInputStream != null) {
fileInputStream.close();
}
}
return null;
}
public void copyFile(byte[] result) throws IOException {
FileOutputStream fileOutputStream = null;
try {
File newFile = new File("C:\\copyFile.log");
fileOutputStream = new FileOutputStream(newFile);
fileOutputStream.write(result);
fileOutputStream.write("复制成功了".getBytes());
fileOutputStream.flush();
fileOutputStream.close();
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}finally{
if (fileOutputStream != null) {
fileOutputStream.close();
}
}
}
public static void main(String[] args) {
CopyFile copyFile = new CopyFile();
byte[] result;
try {
result = copyFile.getFile();
copyFile.copyFile(result);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
java实现文件copy
最新推荐文章于 2024-09-14 22:11:27 发布