当前位置: 代码迷 >> Web前端 >> 资料重命名与复制
  详细解决方案

资料重命名与复制

热度:511   发布时间:2012-08-25 10:06:20.0
文件重命名与复制 .
public static void setFile(){
		/*for (int i = 1; i < 11; i++) {
			String url="D://picture//"+i+"//";
			int end=20*i;
			int start=end-20;
			for (int j = 1; j <=20; j++) {
				File file=new File(url+j+".jpg");
				file.renameTo(new File(url+(j+start)+".jpg"));
				File file1=new File(url+j+"_diff.jpg");
				file1.renameTo(new File(url+(j+start)+"_diff.jpg"));
				File file2=new File(url+j+".xml");
				file2.renameTo(new File(url+(j+start)+".xml"));
			}
			System.out.println("完成第"+i+"个文件的重命名");
		}
		System.out.println("全部完成");*/
		String url="D://151";
		for (int i = 6; i < 11; i++) {//文件夹
			int end=20*i;
			int start=end-20;
			for (int j = 1; j <=20; j++) {//文件
//				File file0=new File(url+j+".jpg");
//				File file1=new File(url+j+"_diff.jpg");
//				File file2=new File(url+j+".xml");
//					File file=new File(url+"//"+i+"//"+(j+start)+".jpg");
//					File file=new File(url+"//"+i+"//"+(j+start)+"_diff.jpg");
					File file=new File(url+"//"+i+"//"+(j+start)+".xml");
					File file2=new File(url,file.getName());
					try {
						FileInputStream fileInputStream=new FileInputStream(file);
						FileOutputStream fileOutputStream=new FileOutputStream(file2);
						byte []buffer=new byte[2048]; 
						int bytes_read;
						try {
							while((bytes_read=fileInputStream.read(buffer))!=-1){
								fileOutputStream.write(buffer,0,bytes_read);
							}
						} catch (IOException e) {
							// TODO Auto-generated catch block
							e.printStackTrace();
						}
						finally{
							try {
								fileInputStream.close();
								fileOutputStream.close();
							} catch (IOException e) {
								// TODO Auto-generated catch block
								e.printStackTrace();
							}
							}
						} catch (FileNotFoundException e) {
							e.printStackTrace();
						}
				}
				
			
			System.out.println("完成"+i);
		}
	}
  相关解决方案