在这个颜值当道,屌丝闪边的时代,拼不过颜值拼内涵,只有知识丰富才能提升一个人的内在气质和修养,所谓人丑就要多学习,今天图老师给大家分享java 实现文件复制和格式更改的实例,希望可以对大家能有小小的帮助。
【 tulaoshi.com - 编程语言 】
代码如下:
package com.chen.lucene.image;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
public class Change2Image
{
 /**复制文件
  * 
  * @author chen_weixian
  * Mar 11, 2012   11:33:19 PM
  * @param path 需要复制文件的路径
  * @param savePath 文件保存路径(复制到的路径)
  * @throws Exception
  */
 public void change2Image(String path, String savePath) throws Exception
 {
  File file = new File(path);
  if (!file.exists())
  {
   System.out.println("文件不存在!");
   return ;
  }
  // 复制到的路径如不存在就创建
  File saveFile = new File(savePath);
  if (!saveFile.exists())
  {
   saveFile.mkdirs();
  }
  // 新文件全路径
  String savePathNew = "";
  for (File fbean : file.listFiles())
  {
   if (fbean.isFile())
   {
    System.out.println(fbean.getName() + "t" + fbean.getAbsolutePath());
//    savePathNew = savePath + File.separator + fbean.getName()+ ".jpg";
    // 把文件名称中含有.tbi格式的转化为.jpg格式  
    savePathNew = savePath + File.separator + (fbean.getName().replaceAll(".tbi", ".jpg"));
    // 开始复制 
             copy(fbean ,new File(savePathNew));      
   }
  }
 }
 /**拷贝文件
  * 
  * @author chen_weixian
  * Mar 11, 2012   11:31:59 PM
  * @param fromFile
  * @param toFile
  * @throws Exception
  */
 private static void copy(File fromFile, File toFile) throws Exception{  
  if (!fromFile.exists())
  {
   System.out.println("
                        
来源:http://www.tulaoshi.com/n/20160219/1596442.html
看过《java 实现文件复制和格式更改的实例》的人还看了以下文章 更多>>