花间一壶酒

导航

将一个文件保存在另一个路径下,并重命名

import java.io.*;
import java.util.Date;

public class BackTest {
static int BUFFER_SIZE = 1024;
public static void main(String[] args) {
int len=0;
String fileName = "E:\\a.txt";
String path = "E:\\a";
System.out.println("保存图像方法");
String latterpart= fileName.substring(fileName.lastIndexOf( "." ));
String imagePath=path+"\\"+new Date().getTime()+latterpart;
System.out.println("保存好的图像的路径为"+imagePath);

String imageName=imagePath.substring(imagePath.lastIndexOf( "\\" )+1);
File myFile = new File("E:\\a.txt");
FileOutputStream fos;
try {
fos = new FileOutputStream(imagePath);
FileInputStream fis=new FileInputStream(myFile);
byte[] buffer=new byte[BUFFER_SIZE];
while((len=fis.read(buffer))>0){
fos.write(buffer,0,len);
}
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}

}
}

写的挺乱的,先粘贴上,日后在修改一下。

posted on 2011-10-07 16:26  wrh526  阅读(378)  评论(0编辑  收藏  举报