package PbuliClass;
|
import java.io.File;
|
import java.io.FileInputStream;
|
import java.io.FileNotFoundException;
|
import java.io.FileOutputStream;
|
import java.io.IOException;
|
import javax.swing.JFileChooser;
|
import javax.swing.JPanel;
|
import javax.swing.filechooser.FileNameExtensionFilter;
|
|
/**ÎļþÏÂÔØÀàÓÃÓÚÏÂÔØÒ»¸öÒѾ´æÔÚµÄÎļþ*/
|
public class DownloadFile {
|
File file=null;
|
File outfile=null;
|
JFileChooser chooser;
|
FileNameExtensionFilter filter;//Îļþ¹ýÂËÆ÷
|
FileOutputStream out=null;//ÎļþÊä³öÁ÷
|
FileInputStream in= null;//ÎļþÊäÈëÁ÷
|
String filePath=null;
|
String fileName=null;//±£´æµÄÎļþÃû³Æ
|
public DownloadFile() {//¹¹Ôì·½·¨
|
|
}
|
|
public String getFilePath() {
|
return filePath;
|
}
|
|
/**ÉèÖÃÔ´ÎļþµÄ·¾¶*/
|
public void setFilePath(String filePath) {
|
this.filePath = filePath;
|
}
|
|
public String getFileName() {
|
return fileName;
|
}
|
|
/**ÉèÖñ£´æÎļþµÄÃû³Æ*/
|
public void setFileName(String fileName) {
|
this.fileName = fileName;
|
}
|
|
/**ÏÂÔØÈËÔ±ÐÅÏ¢±í·½·¨*/
|
public void dowPersonFile(JPanel jpan) {
|
setFilePath("systemFiles/sourse/ÈËÔ±ÐÅÏ¢±í.xls");
|
setFileName("ÈËÔ±ÐÅÏ¢±í.xls");
|
DownloadFilein(jpan);
|
|
}
|
|
/**ÏÂÔØ»ùÕ¾µ¼ÈëÄ£°å·½·¨*/
|
public void downAnchorFile(JPanel jpan) {
|
setFilePath("systemFiles/sourse/»ùÕ¾µ¼ÈëÄ£°å.xls");
|
setFileName("»ùÕ¾µ¼ÈëÄ£°å.xls");
|
DownloadFilein(jpan);
|
|
}
|
|
/**ÏÂÔØ±êÇ©IDµ¼ÈëÄ£°å·½·¨*/
|
public void downTagIdFile(JPanel jpan) {
|
setFilePath("systemFiles/sourse/±êÇ©IDµ¼ÈëÄ£°å.xls");
|
setFileName("±êÇ©IDµ¼ÈëÄ£°å.xls");
|
DownloadFilein(jpan);
|
|
}
|
|
/**ÏÂÔØÎļþµÄ·½·¨*/
|
public void DownloadFilein(JPanel jpan){
|
chooser = new JFileChooser();
|
file=new File(getFilePath());
|
int option = chooser.showSaveDialog(jpan);// Èç¹ûÈ·¶¨Ôò·µ»Ø0£¬È¡Ïû»ò¹Ø±Õ·µ»Ø1
|
if (option == JFileChooser.APPROVE_OPTION){
|
String outName=chooser.getSelectedFile().getAbsolutePath()+getFileName();//µ¼³öµÄÎļþÃû×ÖĬÈÏΪexcelÎļþ
|
outfile=new File(outName);
|
try {
|
in=new FileInputStream(file);
|
out=new FileOutputStream(outfile);
|
int len;
|
try {
|
len = in.read();
|
while (len!=(-1))
|
{
|
out.write(len);
|
len = in.read();
|
}
|
} catch (IOException e1) {
|
e1.printStackTrace();
|
}
|
|
try {
|
out.flush();//Çå¿Õ»º´æ
|
} catch (IOException e) {
|
e.printStackTrace();
|
}
|
} catch (FileNotFoundException e) {
|
e.printStackTrace();
|
}finally{
|
if(in !=null) {
|
try {
|
in.close();
|
} catch (IOException e) {
|
e.printStackTrace();
|
}
|
}
|
if(out !=null) {
|
try {
|
out.close();
|
} catch (IOException e) {
|
e.printStackTrace();
|
}
|
}
|
|
}
|
ShowMessage.zidingyi(outName+"ÏÂÔØ³É¹¦£¡");
|
}
|
}
|
|
|
}
|