如何使用字节流与字节数组实现高效数据拷贝?
- 内容介绍
- 文章标签
- 相关推荐
本文共计145个文字,预计阅读时间需要1分钟。
javaimport java.io.FileInputStream;import java.io.FileNotFoundException;import java.io.FileOutputStream;import java.io.IOException;
public class Test5 { public static void main(String[] args) throws IOException { // 获取要复制的资源File
import java.io.FileInputStream;import java.io.FileNotFoundException;import java.io.FileOutputStream;import java.io.IOException;public class Test5 { public static void main(String[] args) throws IOException { // 获取要拷备的资源 FileInputStream fileInputStream = new FileInputStream("apple.png"); // 获取要保存的目标 FileOutputStream fileOutputStream = new FileOutputStream("拷备apple.png"); // 边读。边写 byte[] bytes = new byte[100]; int len = fileInputStream.read(bytes); while (len != -1) { // 写数据 fileOutputStream.write(bytes, 0, len); // 重新再来yao一下 len = fileInputStream.read(bytes); } // 关闭资源 fileInputStream.close(); fileOutputStream.close(); System.out.println("game over"); }}本文共计145个文字,预计阅读时间需要1分钟。
javaimport java.io.FileInputStream;import java.io.FileNotFoundException;import java.io.FileOutputStream;import java.io.IOException;
public class Test5 { public static void main(String[] args) throws IOException { // 获取要复制的资源File
import java.io.FileInputStream;import java.io.FileNotFoundException;import java.io.FileOutputStream;import java.io.IOException;public class Test5 { public static void main(String[] args) throws IOException { // 获取要拷备的资源 FileInputStream fileInputStream = new FileInputStream("apple.png"); // 获取要保存的目标 FileOutputStream fileOutputStream = new FileOutputStream("拷备apple.png"); // 边读。边写 byte[] bytes = new byte[100]; int len = fileInputStream.read(bytes); while (len != -1) { // 写数据 fileOutputStream.write(bytes, 0, len); // 重新再来yao一下 len = fileInputStream.read(bytes); } // 关闭资源 fileInputStream.close(); fileOutputStream.close(); System.out.println("game over"); }}
