|
楼主 |
发表于 2017-5-19 17:52:21
|
显示全部楼层
本帖最后由 qweasdzxc 于 2017-5-19 18:33 编辑
1.我现在文件是下载到G:/files,想在JAVA代码里想获取X5所在路径怎么获取?
2.如果有多个文件,代码报错
- //不存在
- 11111111111111111111111
- 2017-05-19 18:21:54 [SQL Time]sql 执行时间:2ms, exec KSQL: select SA_DocNode, SA_DocNode.sParentID, SA_DocNode.sDocName, SA_DocNode.sSequence, SA_DocNode.sSize, SA_DocNode.sKind, SA_DocNode.sDocPath, SA_DocNode.sDocDisplayPath, SA_DocNode.sCreatorFID, SA_DocNode.sCreatorName, SA_DocNode.sCreatorDeptName, SA_DocNode.sCreateTime, SA_DocNode.sEditorFID, SA_DocNode.sEditorName, SA_DocNode.sEditorDeptName, SA_DocNode.sLastWriterFID, SA_DocNode.sLastWriterName, SA_DocNode.sLastWriterDeptName, SA_DocNode.sLastWriteTime, SA_DocNode.sFileID, SA_DocNode.sDescription, SA_DocNode.sDocLiveVersionID, SA_DocNode.version, SA_DocNode.sFinishTime, SA_DocNode.sClassification, SA_DocNode.sKeywords, SA_DocNode.sDocSerialNumber, SA_DocNode.sNameSpace, SA_DocNode.sFlag, SA_DocNode.sCacheName, SA_DocNode.sRevisionCacheName from SA_DocNode SA_DocNode where 1=1 and SA_DocNode.sFlag = 1 and SA_DocNode.sDocPath ='/defaultDocNameSpace'
- --> sql:SELECT SA_DocNode.sID, SA_DocNode.sParentID AS sParentID, SA_DocNode.SDOCNAME AS sDocName, SA_DocNode.SSEQUENCE AS sSequence, SA_DocNode.SSIZE AS sSize, SA_DocNode.SKIND AS sKind, SA_DocNode.SDOCPATH AS sDocPath, SA_DocNode.SDOCDISPLAYPATH AS sDocDisplayPath, SA_DocNode.SCREATORFID AS sCreatorFID, SA_DocNode.SCREATORNAME AS sCreatorName, SA_DocNode.SCREATORDEPTNAME AS sCreatorDeptName, SA_DocNode.SCREATETIME AS sCreateTime, SA_DocNode.SEDITORFID AS sEditorFID, SA_DocNode.SEDITORNAME AS sEditorName, SA_DocNode.SEDITORDEPTNAME AS sEditorDeptName, SA_DocNode.SLASTWRITERFID AS sLastWriterFID, SA_DocNode.SLASTWRITERNAME AS sLastWriterName, SA_DocNode.SLASTWRITERDEPTNAME AS sLastWriterDeptName, SA_DocNode.SLASTWRITETIME AS sLastWriteTime, SA_DocNode.SFILEID AS sFileID, SA_DocNode.SDESCRIPTION AS sDescription, SA_DocNode.SDOCLIVEVERSIONID AS sDocLiveVersionID, SA_DocNode.VERSION AS version, SA_DocNode.SFINISHTIME AS sFinishTime, SA_DocNode.SCLASSIFICATION AS sClassification, SA_DocNode.SKEYWORDS AS sKeywords, SA_DocNode.SDOCSERIALNUMBER AS sDocSerialNumber, SA_DocNode.SNAMESPACE AS sNameSpace, SA_DocNode.SFLAG AS sFlag, SA_DocNode.SCACHENAME AS sCacheName, SA_DocNode.SREVISIONCACHENAME AS sRevisionCacheName FROM SA_DocNode SA_DocNode WHERE (? = ?) AND (SA_DocNode.SFLAG = ?) AND (SA_DocNode.SDOCPATH = ?)
- --> binds:[1, 1, 1, /defaultDocNameSpace]
- 2222222222222222222222222
- 2017-05-19 18:21:54 excute stream action, params:{"accept":"application/json","action":"downloadAllAction","actionFlag":"__action_0__","activity":"listActivity","contentType":"json","executeContext":"","executor":"","parameters":{"fAssetAccessory":"[{"docID":"C7888D00C0300001C6966FD49BF8D3D0","docName":"组织机构以及用户密码.xlsx","size":"11583","docPath":"/defaultDocNameSpace","fileID":"96-defaultDocNameSpace","time":"2017-05-19T17:57:04.644Z"},{"docID":"C7888D0192A00001A0B41B0019ED67A0","docName":"测试.docx","size":"12946","docPath":"/defaultDocNameSpace","fileID":"97-defaultDocNameSpace","time":"2017-05-19T17:57:04.646Z"},{"docID":"C7888D029AE000013D9E191ACE841AA0","docName":"软件资产库管理_需求规格说明书V1.0(20160603).doc","size":"2732032","docPath":"/defaultDocNameSpace","fileID":"98-defaultDocNameSpace","time":"2017-05-19T17:57:04.649Z"}]"},"process":"/SAM/assetManage/process/assetout/assetoutProcess"}
- java.lang.reflect.InvocationTargetException
- at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
- at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
- at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
- at java.lang.reflect.Method.invoke(Method.java:497)
- at com.justep.system.action.Engine.invokeActions(Native Method)
- at com.justep.system.action.Engine.invokeActions(Unknown Source)
- at com.justep.business.server.BusinessServer.doAction(Unknown Source)
- at com.justep.business.server.BusinessServer.doExcute(Unknown Source)
- at com.justep.business.server.BusinessServer.excute(Unknown Source)
- at com.justep.business.server.BusinessServer.excute(Unknown Source)
- at com.justep.business.server.BusinessServerServlet.execService(Unknown Source)
- at com.justep.business.server.BusinessServerServlet.service(Unknown Source)
- at javax.servlet.http.HttpServlet.service(HttpServlet.java:723)
- at com.justep.x.bs.BusinessServerServlet.service(Unknown Source)
- at javax.servlet.http.HttpServlet.service(HttpServlet.java:723)
- at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
- at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
- at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
- at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
- at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
- at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:103)
- at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
- at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:293)
- at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:861)
- at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:606)
- at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489)
- at java.lang.Thread.run(Thread.java:745)
- Caused by: java.lang.NullPointerException
- at AssetManage.downloadAll(AssetManage.java:593)
- ... 27 more
复制代码- public static String downloadAll(String fAssetAccessory){
- Docs docs = new Docs();
- File file = new File("G:/files");
- deleteAllFilesOfDir(file);
- if (!file .exists() && !file .isDirectory())
- {
- System.out.println("//不存在");
- file .mkdir();
- } else
- {
- System.out.println("//目录存在");
- }
- String fileName=null;
- String attachmentInfo = fAssetAccessory;//获取到存储附件信息的字段值
- JSONArray ja = JSONArray.parseArray(attachmentInfo);//把json传转换为JSONArray对象
- for (int i = 0; i < ja.size(); i++) {//解析JSONArray获取具体的附件信息
- JSONObject jsonObject = ja.getJSONObject(i);
- String docID = jsonObject.getString("docID");
- String docPath = jsonObject.getString("docPath");
- System.out.println("11111111111111111111111");
- if(docID!=null && docPath!=null){
- com.justep.doc.Doc doc = docs.query(null, docPath, null, null, null).get(docID);
- System.out.println("2222222222222222222222222");
- File outPutFile =new File("G:/files/"+doc.getsDocName());
- System.out.println("333333333333333333333333333333");
- try {
- System.out.println("44444444444444444444444444444444");
- doc.download(new FileOutputStream(outPutFile));
- System.out.println("555555555555555555555555555555");
- ZipMultiFile("G:/files/", "G:/files.zip");
- System.out.println("6666666666666666666666666666666666");
- fileName="G:/files.zip";
- } catch (FileNotFoundException e) {
- // TODO 自动生成的 catch 块
- e.printStackTrace();
- } catch (Exception e) {
- // TODO 自动生成的 catch 块
- e.printStackTrace();
- }
- }
- }
- return fileName;
-
- }
- /** 一次性压缩多个文件,文件存放至一个文件夹中*/
- public static void ZipMultiFile(String filepath ,String zippath) {
- try {
- File file = new File(filepath);// 要被压缩的文件夹
- File zipFile = new File(zippath);
- InputStream input = null;
- ZipOutputStream zipOut = new ZipOutputStream(new FileOutputStream(zipFile));
- if(file.isDirectory()){
- File[] files = file.listFiles();
- for(int i = 0; i < files.length; ++i){
- input = new FileInputStream(files[i]);
- zipOut.putNextEntry(new ZipEntry(file.getName() + File.separator + files[i].getName()));
- int temp = 0;
- while((temp = input.read()) != -1){
- zipOut.write(temp);
- }
- input.close();
- }
- }
- zipOut.close();
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
- public static void deleteAllFilesOfDir(File path) {
- if (!path.exists())
- return;
- if (path.isFile()) {
- path.delete();
- return;
- }
- File[] files = path.listFiles();
- for (int i = 0; i < files.length; i++) {
- deleteAllFilesOfDir(files[i]);
- }
- path.delete();
- }
复制代码
|
|