Copy Code code as follows:
Package com.chen.lucene.image;
Import Java.io.File;
Import Java.io.FileInputStream;
Import Java.io.FileOutputStream;
public class Change2image
{
/** Copy Files
*
* @author Chen_weixian
* 11:33:19 PM
* @param path needs to copy files
* @param savepath File Save path (copied to)
* @throws Exception
*/
public void Change2image (string path, String savepath) throws Exception
{
File File = new file (path);
if (!file.exists ())
{
SYSTEM.OUT.PRINTLN ("file does not exist!") ");
return;
}
The path copied to is created if it does not exist
File SaveFile = new file (Savepath);
if (!savefile.exists ())
{
Savefile.mkdirs ();
}
New file Full path
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";
The file name contains the. TBI format converted to. jpg format
Savepathnew = Savepath + File.separator + (Fbean.getname (). ReplaceAll (". TBI", ". jpg"));
Start replication
Copy (Fbean, new File (savepathnew));
}
}
}
/** Copy Files
*
* @author Chen_weixian
* 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 ("Source file is empty!") ");
}
if (!tofile.exists ())
{
System.out.println ("Create New file ... ");
Tofile.createnewfile ();
}
FileInputStream fis = new FileInputStream (fromfile);
System.out.println ("FromFile:" + Fromfile.getabsolutepath ());
FileOutputStream fos = new FileOutputStream (tofile);
System.out.println ("ToFile:" + Tofile.getabsolutepath ());
int len = 0;
byte[] buf = new byte[1024];
while (len = Fis.read (buf))!=-1) {
Fos.write (Buf,0,len);
}
Fis.close ();
Fos.close ();
}
/** Test
* @author Chen_weixian
* 10:19:56 PM
* @param args
*/
public static void Main (string[] args)
{
String Path = "E:/temp";
String path = "E:/TEMP/3 month packet (1)/March packet";
String Savepath = "e:/temp/img";
Change2image change2image = new Change2image ();
Try
{
Change2image.change2image (path, savepath);
}
catch (Exception e)
{
E.printstacktrace ();
}
System.out.println ("complete");
}
}