在C/S架构中,用java实现下载Excel模板的功能
遇到一个棘手的问题,在C/S架构中,用java实现下载Excel模板的功能,在网络查的都是jsp的方式,没有找到C/S架构的,我是用swing做的,把Excel放到了一个项目文件夹中,用户下载的时候直接下载到用户选择的路径中,该怎么实现 ,我用这种方式实现的,但是有问题
protected void loadTemplateAction_actionPerformed(ActionEvent e) throws Exception {
JFileChooser chooser = new JFileChooser();
//要想添加默认的文件名,需将setSelectedFile()这个方法放到打开对话框之前
String defaultFileName = "customers.csv";
chooser.setSelectedFile(new File(defaultFileName));
chooser.showSaveDialog(this);
FileInputStream fis = null;
FileOutputStream fos = null;
String sourcefileUrl = "ini/template1/customers.csv";
String outUrl = chooser.getCurrentDirectory().getPath();
File sourceFile = new File(sourcefileUrl);
File targetFile = new File(outUrl);
fis = new FileInputStream(sourceFile);
byte[] b = new byte[(int) sourceFile.length()];
int len = fis.read(b);
while(len>0){
fos = new FileOutputStream(targetFile);
System.out.println("len:"+len);
System.out.println("os:"+fos);
fos.write(b, 0, len);
fos.flush();
}
fis.close();
contentFileNameText.setText("模板下载成功...");
}
请大家帮帮忙,谢谢了
protected void loadTemplateAction_actionPerformed(ActionEvent e) throws Exception {
JFileChooser chooser = new JFileChooser();
//要想添加默认的文件名,需将setSelectedFile()这个方法放到打开对话框之前
String defaultFileName = "customers.csv";
chooser.setSelectedFile(new File(defaultFileName));
chooser.showSaveDialog(this);
FileInputStream fis = null;
FileOutputStream fos = null;
String sourcefileUrl = "ini/template1/customers.csv";
String outUrl = chooser.getCurrentDirectory().getPath();
File sourceFile = new File(sourcefileUrl);
File targetFile = new File(outUrl);
fis = new FileInputStream(sourceFile);
byte[] b = new byte[(int) sourceFile.length()];
int len = fis.read(b);
while(len>0){
fos = new FileOutputStream(targetFile);
System.out.println("len:"+len);
System.out.println("os:"+fos);
fos.write(b, 0, len);
fos.flush();
}
fis.close();
contentFileNameText.setText("模板下载成功...");
}
请大家帮帮忙,谢谢了
...全文
相关推荐
IReport使用指南
此文档对IReport一个总结,包括报表开发,Jasperreport,IReport,等等的描述,相信对你有一定的帮助
水晶报表的jsp实现(开发工具bea weblogic workshop).doc
水晶报表的jsp实现(开发工具bea weblogic workshop).doc水晶报表的jsp实现(开发工具bea weblogic workshop).doc
Java实现C/S架构的聊天系统
基于C/S架构的聊天系统的实现, 运用NIO机制 Socket通信,通过多线程IO操作等技术实现好友添加,删除好友,好友聊天,文件互传功能,可用于java语言的练习与提高
JAVA C/S架构应用程序
用JAVA开发的一个简单桌面应用程序,实现ORACLE数据库的增删改查操作,所有操作均用存储过程实现,同时实现了Oracle 大对象BLOB 图像文件的存取,供初学者学习。
基于Java实现C/S架构的聊天系统
基于C/S架构的聊天系统的实现, 运用NIO机制 Socket通信,通过多线程IO操作等技术实现好友添加,删除好友,好友聊天,文件互传功能,可用于java语言的练习与提高


