簡易實現, txt檔案顯示在html上
<textarea data-dojo-attach-point="txtViewForm" style="font-ize: 15px; width: 100%;height: 100%" readonly="readonly" > this.txtViewForm.value = content; /** * 綜合利用,線上預覽 txt格式附件 * @param osName * @param docId * @throws EcmException * @throws IOException */ public static String downloadPrimaryAttach(String osName, String docId) throws EcmException, IOException { EntityManager em = null; try { em = DaoManager.getEntityManager(); ObjectStore os = ObjectStoreHelper.getObjectStore(osName); Document doc = P8DocumentDao.fetchDocumentById(os, docId); Collection<ContentTransfer> collection = EngineCollectionUtils.c(doc.get_ContentElements(), ContentTransfer.class); Iterator<ContentTransfer> it = collection.iterator(); ContentTransfer content = it.next(); InputStream in = content.accessContentStream(); StringBuffer sb = new StringBuffer(); //根據特徵碼,來判斷文字檔案編碼格式,目前版本不支援全部格式轉換 //在網路上查詢資料,沒有找到可用的覆蓋面比較廣的特徵碼集合。求各位大神分享。 byte[] head = new byte[3]; in.read(head); String code = "GBK"; if (head[0] == -1 && head[1] == -2 ) { //txt編碼為utf8 code = "UTF-8"; }else if (head[0] == -2 && head[1] == -1 ){ //txt編碼為Unicode code = "UTF-16"; }else if(head[0]==-17 && head[1]==-69 && head[2] ==-65){ //txt編碼為UTF-8 code = "UTF-8"; }else if(head[0]==49 && head[1]==46 && head[2] ==-44){ //[49, 46, -44] code ="GB2312"; } Charset charset = Charset.forName(code); //此處需要設定charset,以便很好的控制頁面上文字的亂碼問題。 InputStreamReader reader = new InputStreamReader(in,charset); BufferedReader bfreader = new BufferedReader(reader); String content1 = ""; while(content1 != null){ content1 = bfreader.readLine(); if(content1 == null){ break; } sb.append(content1.trim()); sb.append("\r\n"); } return sb.toString(); } catch (Exception e) { logger.error("downloadAttach error", e); throw new EcmException(ErrorCode.ATTACHMENT_DOWNLOAD_ERROR, "downloadAttach error ", e); } finally { if (em != null) { em.close(); } } }
相關推薦
簡易實現, txt檔案顯示在html上
<textarea data-dojo-attach-point="txtViewForm" style="font-ize: 15px; width: 100%;height: 100%" readonly="readonly" > this.txtViewForm.value
vue+element+springboot實現.txt檔案上傳
前端html程式碼 <div class="p-upload-box"> <form action='dic/uploadWord' enctype='multipart/form-data' method='post' id="fileUpl
讀取txt檔案顯示到treeview上
//將檔案內容讀取然後顯示到列表上 ClearTree(); StreamReader sr = new StreamReader(localpath, Encoding.Default);
springboot 整合 gridfs 、webUploader實現大檔案分塊上傳、斷點續傳、秒傳
主要的pom.xml: <dependency> <groupId>mysql</groupId> <artifactId>mysql-connector-java</artifactId>
txt 檔案在伺服器上的 讀取及寫入
做的外圍資料對接,報文引數較多,資料庫存不下,只好用txt了, 自己 備用 public class MyFileUtils { /** * @param txt 寫入的內容 * @param channel 來源 * @par
QT讀寫TXT檔案顯示中文
分享一下我老師大神的人工智慧教程!零基礎,通俗易懂!http://blog.csdn.net/jiangjunshow 也歡迎大家轉載本篇文章。分享知識,造福人民,實現我們中華民族偉大復興!  
C# 中WinForm 應用程式實現遠端檔案管理(上傳、下載)的種種問題——遠端伺服器返回錯誤
C# 中WinForm 應用程式實現遠端檔案管理(上傳、下載)的種種問題 WinForm可以通過C#語言提供的WebClient類的UploadFile和DownLoadFile函式實現檔案的上傳和下載功能,但是這也讓我嘗試到了使用這個函式時的辛酸,搞了整整一天才
MapReduce程式設計實現txt檔案中的內容匯入HBase
一、建立java專案。 寫入程式碼,如下: [java] view plain copy print? package translate1; import java.io.IOException; import org.apache.hadoo
C++ 實現txt檔案的讀取
最近臨時接到專案,加緊學習了一下C++,只是簡單的檔案的讀取就弄了好久的說~~ 現在特意分享一下,希望對小夥伴們會有幫助喔~~ 1. 實現txt檔案的讀入並重寫入另外一個txt檔案中~ #include<fstream> //ifstream #include
Lucene 實現txt檔案的構建索引與查詢
package net.jqsoft.hecv.util; import net.sf.json.JSONArray; import org.apache.lucene.analysis.Analyzer; import org.apache.lucene.analysis
python 實現txt檔案 按 value值排序從高到低
with open('sort.txt','w+') as w: while True: sorted_lines=sorted(open('1.txt'), key=lambda s: s.split()[4],reverse=1)
HTML 上傳檔案、過濾型別以及顯示大小
HTML: <h>檔案上傳只支援.xlsx格式</h> <form action="/upload" method="post" enctype="multipart/form-data"> <input type="file"
js實現檔案拖拽上傳並顯示待上傳的檔案列表
首先實現html頁面的內容:<body> <div name="single" style="text-align: center; "> <A class=btn_addPic href="javascript:void
用struts2實現上傳檔案和轉化檔案為html
action public class shangchuanAction extends ActionSupport{ public File some; public String someFileName; public File getSome() { return so
layui.js實現多檔案上傳前端html寫法總結
最近需要寫多檔案上傳功能,用到了layui.js控制元件,現進行總結,因為內容太多這裡只總結了html頁面的內容,java後臺配置對接另一篇文章《layui上傳多檔案後臺程式碼總結(java》,其實官網《layui.js檔案上傳示例》已經寫的很詳細了,我再囉嗦一下。 參考文章如下: layu
HTML上顯示渲染PDF檔案外掛PDFObject(自帶下載功能),超強,附外掛下載地址
非常好用的h5上顯示pdf外掛,可以列印,全屏預覽,下載,旋轉等。 用法: 1.引入pdfobject.js <script src="js/pdfobject.js" type="text/javascript" charset="utf-8">&
webuploader+springmvc實現多檔案上傳(html+js+css原創,後臺程式碼借鑑)
———————-css—————————- /*新增圖片按鈕*/ .add_resume_item { cursor: pointer; } /*遮罩層*/ .zpzs_gray { position: fixed; left: 0; to
html實現鈍角效果;html實現限制一行字數的顯示,超出的部分用省略號(....)來代替
button posit uitext 鄙視 gulp 最新 完全 經典 ava 前端實現div框邊角的鈍化雖然簡單,但是有時候突然想不到,特此寫下幾句實現方法,以便記憶。 實現div框四個角都鈍角的操作:設置 div : border-radius=10p
Ubuntu 16.04安裝indicator-sysmonitor實現導航條顯示上下行網速/CPU/內存使用率
mem cnblogs http sudo images ica cpu 上下 實現 安裝: sudo add-apt-repository ppa:fossfreedom/indicator-sysmonitor sudo apt-get update sudo
C#實現FTP檔案的上傳、下載功能、新建目錄以及檔案的刪除
轉載至:https://www.cnblogs.com/zhenzaizai/p/7434669.html using System; using System.Collections.Generic;