标签:ade layout size 字节流 文件 数据 except line add
public class CopyDemo { //第一步:将1.txt中的内容读入到内存 FileInputStream //第二步:将内存中读入的数据读入到2.txt FileOutputStream //使用字节流来copy东西不会出现乱码,因为是把所有东西照搬过去,没有拿出来解析 public static void main(String[] args) throws IOException { FileInputStream fis = new FileInputStream("我的滑板鞋.mp4"); //任何文件格式都可以拷贝 FileOutputStream fos = new FileOutputStream("kaobei.mp4"); | //方法一: 效率低下,一次一个字节 /* int b = 0; while((b = fis.read()) != -1){ fos.write(b); }*/ //方法二: 效率高,一次整个数组 byte[] bytes = new byte[1024]; int len = 0; while((len = fis.read(bytes)) != -1){ fos.write(bytes,0,len); } fis.close(); fos.close(); } } |
public class BufferTestMain { public static void main(String[] args) throws IOException { FileInputStream fis = new FileInputStream("我的滑板鞋.mp4"); // 这样的fis不带缓冲区 BufferedInputStream bfis = new BufferedInputStream(fis); FileOutputStream fos = new FileOutputStream("kaobei.mp4"); BufferedOutputStream bfos = new BufferedOutputStream(fos); | // 方法一: /* int b = 0; while ((b = bfis.read()) != -1) { //看上去是一个字节一个字节的读,其实系统实现是一次读 8192 个字节到缓冲区 bfos.write(b); }*/ // 方法二:更快,缓冲区自带一个8192缓冲区,自己还定义了一个1024的缓冲区 byte[] bytes = new byte[1024]; int len = 0; while ((len = bfis.read(bytes)) != -1) { bfos.write(bytes, 0, len); } } } |
标签:ade layout size 字节流 文件 数据 except line add
原文地址:https://www.cnblogs.com/meihao1203/p/9181937.html