资讯

精准传达 • 有效沟通

从品牌网站建设到网络营销策划,从策略到执行的一站式服务

java拷贝图片的代码 java图片复制

java怎样复制图片

图片本质上还是文件,所以就像复制文件一样就可以了。下面是一个演示程序:

创新互联服务项目包括康保网站建设、康保网站制作、康保网页制作以及康保网络营销策划等。多年来,我们专注于互联网行业,利用自身积累的技术优势、行业经验、深度合作伙伴关系等,向广大中小型企业、政府机构等提供互联网行业的解决方案,康保网站推广取得了明显的社会效益与经济效益。目前,我们服务的客户以成都为中心已经辐射到康保省份的部分城市,未来相信会继续扩大服务区域并继续获得客户的支持与信任!

public class CopyImage

{

public static void main(String[] args) throws Exception

{

FileInputStream fi=new FileInputStream("image.jpg");

BufferedInputStream in=new BufferedInputStream(fi);

FileOutputStream fo=new FileOutputStream("cimage.jpg");

BufferedOutputStream out=new BufferedOutputStream(fo);

byte[] buf=new byte[4096];

int len=in.read(buf);

while(len!=-1)

{

out.write(buf, 0, len);

len=in.read(buf);

}

out.close();

fo.close();

in.close();

fi.close();

}

}

运行程序是改一改图片的路径,另外在实际代码中最后不要想上面的代码直接抛出这样的异常。

从文件中读取图片和写入图片到文件里的java代码是什么?

首先导入各种需要的包:

import java.awt.Image;

import javax.imageio.ImageIO;

import java.io.*;

读取图片的方法如下:

Image[] array = new Image[10];

Image image = ImageIO.read(new File("d:\\source.gif"));//根据你实际情况改文件路径吧

array[0] = image;

图片读出来了。

如果你有一个Image对象,想把它写入文件可以这样做:

BufferedImage image = ImageIO.read(new File("d:\\source.gif"));

//要想保存这个对象的话你要把image声明为BufferedImage 类型

ImageIO.write(image, "png", new File("f:\\test.png"));

java中,用OutputStream怎样将存放在D盘中的图片复制到F盘,求代码……

import java.io.File;

import java.io.FileInputStream;

import java.io.FileOutputStream;

import java.io.FilenameFilter;

import java.io.InputStream;

import java.io.OutputStream;

import java.util.Arrays;

import java.util.List;

public class CopyCat

{

private static final ListString STOOGES = Arrays.asList ("png", "gif", "jpg", "jpeg");

private static void copy ( final String src, final String dest, final String suffix )

{

File srcFile = new File (src);

srcFile.listFiles (new FilenameFilter ()

{

@Override

public boolean accept ( File dir, String name )

{

String separator = System.getProperty ("file.separator");

String s = name.substring (name.lastIndexOf ('.') + 1, name.length ());

if (null == suffix || "".equals (suffix) || STOOGES.contains (s))

{

try

{

int read = -1;

InputStream is = new FileInputStream (src + separator + name);

OutputStream os = new FileOutputStream (dest + separator + name);

while (( read = is.read () ) != -1)

{

os.write (read);

}

os.flush ();

os.close ();

is.close ();

}

catch (Exception e)

{}

return true;

}

return false;

}

});

}

public static void main ( String[] args )

{

System.out.println ("正在写入...");

copy ("d:/", "f:/", null);

System.out.println ("已完毕 !");

}

}

用Java编写一个程序,将一个图像文件复制到指定的文件夹中

这是我们公司基类里的一个方法希望对你有帮助。。/**

* 复制单个文件

* @param oldPath String 原文件路径 如:c:/fqf.txt

* @param newPath String 复制后路径 如:f:/fqf.txt

* @return boolean

*/

public void copyFile(String oldPath, String newPath) {

try {

int bytesum = 0;

int byteread = 0;

File oldfile = new File(oldPath);

if (oldfile.exists()) { //文件存在时

InputStream inStream = new FileInputStream(oldPath); //读入原文件

FileOutputStream fs = new FileOutputStream(newPath);

byte[] buffer = new byte[1444];

int length;

while ( (byteread = inStream.read(buffer)) != -1) {

bytesum += byteread; //字节数 文件大小

// System.out.println(bytesum);

fs.write(buffer, 0, byteread);

}

inStream.close();

}

}

catch (Exception e) {

System.out.println("复制单个文件操作出错");

e.printStackTrace(); } }

一个关于JAVA拷贝图片的问题

import java.io.*;

public class BisicImageCopy {

public static void main(String[] args) {

FileInputStream fin = null;

FileOutputStream fout = null;

try {

fin = new FileInputStream("e:\\Car.jpg");

fout = new FileOutputStream("d:\\Car.jpg");

byte[] b = new byte[512];

int n;

while((n = fin.read(b))!=-1){

fout.write(b,0,n);//这里改改

}

} catch (Exception e) {

e.printStackTrace();

}finally{

try {

fin.close();

fout.close();

} catch (IOException e) {

e.printStackTrace();

}

}

}

}

java输入输出流拷贝图片 下面的代码为什么生成的图片打不开还会越来越大

while((n=fis.read(buf))!=-1)

{

fos.write(buf, 0, n);//输出到指定文件

}


当前文章:java拷贝图片的代码 java图片复制
浏览路径:http://cdkjz.cn/article/hhodeg.html
多年建站经验

多一份参考,总有益处

联系快上网,免费获得专属《策划方案》及报价

咨询相关问题或预约面谈,可以通过以下方式与我们联系

大客户专线   成都:13518219792   座机:028-86922220