import java.io.File; import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.IOException;
public class FileIOExample { public static void main(String[] args) { File inputFile = new File(“input.txt”); File outputFile = new File(“output.txt”);
try {
// 读取文件内容并写入到输出文件
FileInputStream input = new FileInputStream(inputFile);
FileOutputStream output = new FileOutputStream(outputFile);
byte[] buffer = new byte[1024];
int bytesRead;
while ((bytesRead = input.read(buffer)) != -1) {
output.write(buffer, 0, bytesRead);
}
// 关闭输入输出流
input.close();
output.close();
System.out.println("文件复制成功!");
} catch (IOException e) {
System.out.println("文件复制失败:" + e.getMessage());
}
}
}