复制文件到目标路径
2012-11-07 17:21
281 查看
不多说 直接上代码 你懂得
import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import javax.imageio.stream.FileImageInputStream;
import javax.imageio.stream.FileImageOutputStream;
public class CopyImage {
/**
* 拷贝图片至新的文件下
* @param oldImgFile 原文件存放路径
* @param newImgFile 新文件存放路径
*/
private static void copyImage(String oldImgFile,String newImgFile){
FileImageInputStream infile=null;
FileImageOutputStream outfile=null;
try {
File filepath=new File(oldImgFile);
infile=new FileImageInputStream(filepath);
byte[] b=new byte[1024*3];
File newfile=new File(newImgFile);
if (!newfile.getParentFile().exists()) {
newfile.getParentFile().mkdirs();
}
outfile=new FileImageOutputStream(newfile);
int bufLength = 0;
while ((bufLength = infile.read(b)) != -1) {
outfile.write(b, 0, bufLength);
outfile.flush();
}
} catch (FileNotFoundException e) {
} catch (IOException e) {
}finally{
try {
if(infile!=null)
{
infile.close();
}
if(outfile!=null){
outfile.close();
}
} catch (IOException e1) {
infile=null;
outfile=null;
}
}
}
public static void main(String[] args){
CopyImage c = new CopyImage();
c.copyImage("F:\\suotu\\sLA20121018B15-001.jpg", "F:\\suotu\\copy\\sLA20121018B15-001_s.jpg");
}
}
import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import javax.imageio.stream.FileImageInputStream;
import javax.imageio.stream.FileImageOutputStream;
public class CopyImage {
/**
* 拷贝图片至新的文件下
* @param oldImgFile 原文件存放路径
* @param newImgFile 新文件存放路径
*/
private static void copyImage(String oldImgFile,String newImgFile){
FileImageInputStream infile=null;
FileImageOutputStream outfile=null;
try {
File filepath=new File(oldImgFile);
infile=new FileImageInputStream(filepath);
byte[] b=new byte[1024*3];
File newfile=new File(newImgFile);
if (!newfile.getParentFile().exists()) {
newfile.getParentFile().mkdirs();
}
outfile=new FileImageOutputStream(newfile);
int bufLength = 0;
while ((bufLength = infile.read(b)) != -1) {
outfile.write(b, 0, bufLength);
outfile.flush();
}
} catch (FileNotFoundException e) {
} catch (IOException e) {
}finally{
try {
if(infile!=null)
{
infile.close();
}
if(outfile!=null){
outfile.close();
}
} catch (IOException e1) {
infile=null;
outfile=null;
}
}
}
public static void main(String[] args){
CopyImage c = new CopyImage();
c.copyImage("F:\\suotu\\sLA20121018B15-001.jpg", "F:\\suotu\\copy\\sLA20121018B15-001_s.jpg");
}
}
相关文章推荐
- 完成文件复制操作,在程序运行后提示输入源文件路径,然后再输入目标文件路径。
- 完成文件复制操作,在程序运行后提示输入源文件路径,然后再输入目标文件路径。
- 完成文件复制操作,在程序运行后提示输入源文件路径,然后再输入目标文件路径。
- 完成文件复制操作,在程序运行后提示输入源文件路径,然后再输入目标文件路径。
- 完成文件复制操作,在程序运行后提示输入源文件路径,然后再输入目标文件路径。
- 完成文件复制操作,在程序运行后提示输入源文件路径,然后再输入目标文件路径。
- 完成文件复制操作,在程序运行后提示输入源文件路径,然后再输入目标文件路径。
- 完成文件复制操作,在程序运行后提示输入源文件路径,然后再输入目标文件路径。
- 完成文件复制操作,在程序运行后提示输入源文件路径,然后再输入目标文件路径。
- 完成文件复制操作,在程序运行后提示输入源文件路径,然后再输入目标文件路径。
- 完成文件复制操作,在程序运行后提示输入源文件路径,然后再输入目标文件路径。
- 习题12:编写程序,将文件复制到指定路径,允许改写同名的目标文件。
- 实现文件复制的功能(从原路径下 复制 图片 到 新路径下 )
- linux学习(6) ls(查看文件,目录) 复制、删除与移动: cp, rm, mv,取得路径的文件名称与目录名称
- 为文件、文件夹添加复制路径的右键菜单
- 一段小程序,把某个文件从A路径按照某速度复制到B路径(python)
- 编程实现文件的复制功能,要求源文件名及目标文件名在程序运行后根据提示输入
- 枚举指定路径下文件及文件夹复制到指定路径下
- PHP获取目标路径的文件目录
- MFC判断某路径下的目标文件是否存在