バイトストリームのコピーの写真

テキストは、画像、ビデオが書かれている、唯一の送信元と送信先のデータはそれを明確にする必要があり
、1つのバイトを読み込み、

//封装数据源
		FileInputStream fis=new FileInputStream("C:\\Users\\29265\\Desktop\\4\\1.png");
		//封装目的地
		FileOutputStream fos=new FileOutputStream("C:\\Users\\29265\\Desktop\\2.png");
		
		int by;
		while((by=fis.read())!=-1){
			fos.write(by);//每次读取一个字节写入
		}
		
		//释放资源,顺序无关
		fis.close();
		fos.close();

1秒に1回、バイト配列が読み込まれ
、この方法は高速です

//封装数据源
		FileInputStream fis=new FileInputStream("C:\\Users\\29265\\Desktop\\4\\1.png");
		//封装目的地
		FileOutputStream fos=new FileOutputStream("C:\\Users\\29265\\Desktop\\3.png");
		
		//数组的大小一般是1024的倍数
		byte[] bs=new byte[1024];
		int len;
		//fis.read(bs)如果找到数据就会返回-1
		while((len=fis.read(bs))!=-1){
			fos.write(bs,0,len);
		}
		
		//释放资源,顺序无关
		fis.close();
		fos.close();
公開された210元の記事 ウォン称賛10 ビュー10000 +

おすすめ

転載: blog.csdn.net/Ting1king/article/details/105009453