import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
/**
* 测试类, 复制文件
* @author Administrator
*
*/
public class Test5 {
public static void main(String[] args) {
try {
//创建IO流对象
File file = new File("file/images/Koala.jpg");
FileInputStream fis = new FileInputStream(file);
FileOutputStream fos = new FileOutputStream("file/test/" + file.getName());
//创建字节数组
byte[] content = new byte[fis.available()];
//读取文件
fis.read(content);
//将文件内容写入输出流
fos.write(content);
//关闭IO资源
fos.close();
fis.close();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
}
复制文件:利用输入输出流
最新推荐文章于 2023-09-17 22:07:06 发布