Extjs--关于文件的上传这几天要做一个页面的上传和下载,从年前一直纠结到现在,一直以为是Extjs基础下的上
Extjs--关于文件的上传
这几天要做一个页面的上传和下载,从年前一直纠结到现在,一直以为是Extjs基础下的上传下载,其实与Extjs基本没有什么关系,只是一直思维被局限于Extjs界面的缘故。听说Extjs4.0有对应的控件,由于目前公司项目非4.0,所以目前暂未实现过,下面记录一下自己目前总结的解决办法。
上传:
public String updateLoad(String filePath, String fatherPath, String path) {String ret="";File upFileDir = new File(path + "\\" + fatherPath);if(!upFileDir.exists()){upFileDir.mkdirs();}String s[] = filePath.split("\\\\");String fileName = s[s.length-1];File inFile = new File(filePath);File outFile = new File(upFileDir.getPath() + "\\" + fileName);FileInputStream fis;FileOutputStream fos;BufferedInputStream bis = null;BufferedOutputStream bos = null;try {fis = new FileInputStream(inFile);fos = new FileOutputStream(outFile);bis = new BufferedInputStream(fis);bos = new BufferedOutputStream(fos);byte[] b = new byte[1024];int len;while ((len = bis.read(b)) != -1) { bos.write(b, 0, len);}bos.flush();} catch (FileNotFoundException e) {e.printStackTrace();ret="文件上传失败!";} catch (IOException e) {e.printStackTrace();ret="文件上传失败!";}finally{try {bis.close();bos.close();} catch (IOException e) {e.printStackTrace();}}return ret;}贴上自己写的项目代码,http://download.csdn.net/detail/nisior/5093021
