import java.io.*;
public class TestFile {
public static void main(String[] args) throws IOException {
File f=new File("c:/kgaga.jpg");
FileInputStream fi=new FileInputStream(f);
FileOutputStream fo=new FileOutputStream(new File("d:/aa.jpeg"));
int k;
int i=0;
byte[] by=new byte[1024];
while(-1!=(k=fi.read(by))){
System.out.println(i++);
fo.write(by);
}
}
}
public class TestFile {
public static void main(String[] args) throws IOException {
File f=new File("c:/kgaga.jpg");
FileInputStream fi=new FileInputStream(f);
FileOutputStream fo=new FileOutputStream(new File("d:/aa.jpeg"));
int k;
int i=0;
byte[] by=new byte[1024];
while(-1!=(k=fi.read(by))){
System.out.println(i++);
fo.write(by);
}
}
}
本文提供了一个使用Java进行文件复制的简单示例。通过FileInputStream和FileOutputStream读写文件,实现从一个位置到另一个位置的文件复制过程。该示例展示了如何逐块读取源文件并写入目标文件。

被折叠的 条评论
为什么被折叠?



