String result=null;
try {
Object media = Fileupload.get("选择Excel文件","上传Excel文件");
if(media!=null && (media instanceof AMedia)){
AMedia aMedia=(AMedia)media;
if(aMedia.getFormat().equals("xls")|| aMedia.getFormat().equals("XLS")){
String postfix="xls";
long timeMillis=System.currentTimeMillis();
String starePath = FileConfig.STORE_SPREADSHEET_PATH+timeMillis+"."+aMedia.getFormat();
String name=aMedia.getName().substring(0,aMedia.getName().toLowerCase().lastIndexOf("."+postfix));
//取得服務器的絕對路徑
//Desktop dtp = Executions.getCurrent().getDesktop();
// realPath = dtp.getSession().getWebApp().getRealPath("your file name or some folder");
FileOutputStream out=new FileOutputStream(contextPath+starePath);
InputStream in = aMedia.getStreamData();//获得输入流
byte[] buf = new byte[1024];
int count= in.read(buf,0,1);
while(count!=-1){
out.write(buf,0,count);
count = in.read(buf,0,count);
}
out.flush();
in.close();
out.close();
}else{
result="你上传的不是Excel文件";
}
}
} catch (InterruptedException e)
{e.printStackTrace();}
catch (FileNotFoundException e)
{e.printStackTrace();}
catch (IOException e)
{e.printStackTrace();}
return result;