java.io provides many stream classes. Here we are going to use FileInputStream/FileOutputStream----for reading raw bytes
( Recommended tutorial: java introductory tutorial)
First we copy a picture into the current directory, for example: "d:/java/TestPicture/image1.jpg", and then we use FileInputStream Read the picture, and finally FileOutputStream generates a picture as image2.jpg in the current directory.
(Video tutorial recommendation: java video tutorial)
java code:
import java.io.*; public class TestPictureCopy{ public static void main(String []args)throws Exception{ //会抛异常,所以我们在主函数中给抛出去 //输入流 FileInputStream fis=new FileInputStream("image1.jpg"); //输出流 FileOutputStream fos=new FileOutputStream("image2.jpg"); //我们用read(byte[]b,int off,int len)函数来读-确保两张图片大小一致,且效率还高 byte[] b=new byte[1024]; int num=0; while((num=fis.read(b,10,1000))!=-1){ fos.write(b,10,num); } fis.close(); fos.close(); } }
See if image1.jpg has been generated in the current directory Replicaimage2.jpg.
The above is the detailed content of How to use io stream to copy pictures in java. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Safe Exam Browser
Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.

WebStorm Mac version
Useful JavaScript development tools

SAP NetWeaver Server Adapter for Eclipse
Integrate Eclipse with SAP NetWeaver application server.

MinGW - Minimalist GNU for Windows
This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

Atom editor mac version download
The most popular open source editor