精华内容
下载资源
问答
  • 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253using System;using System.Data;using System.Configuration;using System.Collections;...

    1

    2

    3

    4

    5

    6

    7

    8

    9

    10

    11

    12

    13

    14

    15

    16

    17

    18

    19

    20

    21

    22

    23

    24

    25

    26

    27

    28

    29

    30

    31

    32

    33

    34

    35

    36

    37

    38

    39

    40

    41

    42

    43

    44

    45

    46

    47

    48

    49

    50

    51

    52

    53

    using System;

    using System.Data;

    using System.Configuration;

    using System.Collections;

    using System.Web;

    using System.Web.Security;

    using System.Web.UI;

    using System.Web.UI.WebControls;

    using System.Web.UI.WebControls.WebParts;

    using System.Web.UI.HtmlControls;

    using System.IO;

    public partial class Default2 : System.Web.UI.Page

    {

    Default2 dr;

    protected void Page_Load(object sender, EventArgs e)

    {

    dr = new Default2();

    string path = Server.MapPath(@"新文件夹1\ww.doc");

    dr.ConvertWord(dr.wordConvertByte(path));

    }

    private byte[] wordConvertByte(string wordPath)

    {

    byte[] bytContent = null;

    FileStream fs = null;

    BinaryReader br = null;

    try

    {

    fs = new FileStream(wordPath, System.IO.FileMode.Open);

    }

    catch(Exception ex)

    {

    Response.Write(ex.Message);

    }

    br = new BinaryReader((Stream)fs);

    bytContent = br.ReadBytes((Int32)fs.Length);

    br.Close();

    fs.Close();

    return bytContent;

    }

    protected void ConvertWord(byte[] data)

    {

    string filepath = Server.MapPath(@"新文件夹1\mr.doc");

    FileStream fs = new FileStream(filepath, FileMode.Create);

    BinaryWriter bw = new BinaryWriter(fs);

    bw.Write(data, 0, data.Length);

    bw.Close();

    fs.Close();

    }

    }

    展开全文
  • Unfortunately, no work is required to convert it the other way either: the "document" view of a Word file is not intrinsic to the file content, it is a layer of "understanding" applied to the data ...

    hello,.,.

    I am new to the code project,in asking questions for the problems.But in many occasions,this would helped me a lot. So first of all i wishto say thnkz you.

    Now iam in a trouble. plz help me..In my project ,iam using 2 modules ,one is encoder and another decoder.

    The encoder will encode the source data(say.Ms Word document file) to binary series(only combination of 0''s and 1''s,no any other format ) and decoder will convert it into original back.please i request t\you to anyboby send me such a type of project with source code.

    Sincerly , asok kumar

    解决方案

    That''s not really what you want, I suspect.

    Your Word documents (and indeed all documents and other files) are already stored as binary bit sequences: that is all the underlying medium - the hard disk, or ram - understands.

    So trying to convert your document to binary format requires no work at all - it is already there. Unfortunately, no work is required to convert it the other way either: the "document" view of a Word file is not intrinsic to the file content, it is a layer of "understanding" applied to the data the Word program reads from the disk. The document is not complete as a Word document without some software to process the file and render it in a form you associate with a letter, or a manual.

    What are you trying to achieve, that you think this will help you?

    展开全文
  • static void Main(string[] args){try{var strParams = new Dictionary();string base64 = string.Empty;var userName = ConfigurationManager.AppSettings["UserName"];PDFSourceBaseGenerator instance= newPDFSou...

    static void Main(string[] args)

    {try{var strParams = new Dictionary();string base64 = string.Empty;var userName = ConfigurationManager.AppSettings["UserName"];

    PDFSourceBaseGenerator instance= newPDFSourceBaseGenerator();var pdfgen = newGeneratePDF();//var pdfData = instance.getDBPDFInfo(38, userName, "TME-20180627");//if (pdfData != null && pdfData.Rows.Count > 0)

    {

    Console.WriteLine("获取数据没问题");var path = $"{AppDomain.CurrentDomain.BaseDirectory}协议书-TME.docx";//pdfContent

    var pdfSourceContent =File.ReadAllBytes(path);//用户默认地址PostalAddress//strParams.Add("${PostalAddress}", pdfData.Rows[0][1] == null ? "" : pdfData.Rows[0][1].ToString());//var PDFContent = instance.getPDFContent(38, strParams, pdfSourceContent, base64);

    var PDFContent = pdfgen.RequestPDF(pdfSourceContent, strParams, 1);if (PDFContent != null)

    {

    File.WriteAllBytes($"{AppDomain.CurrentDomain.BaseDirectory}aaaaaa.doc", PDFContent);

    Console.WriteLine("调用getPDFContent成功");

    }else{

    Console.WriteLine("调用getPDFContent失败");

    }

    PDFContent= pdfgen.RequestPDF(pdfSourceContent, strParams, 0);if (PDFContent != null)

    {

    File.WriteAllBytes($"{AppDomain.CurrentDomain.BaseDirectory}aaaaaa.pdf", PDFContent);

    Console.WriteLine("调用getPDFContent成功");

    }else{

    Console.WriteLine("调用getPDFContent失败");

    }

    }

    }catch(Exception er)

    {

    Console.WriteLine("异常了,exception=" +er.ToString());

    }

    Console.ReadLine();

    }

    展开全文
  • 本篇文章主要介绍了JAVA中读取文件(二进制,字符)内容的方法总结,小编觉得挺不错的,现在分享给大家,也给大家做个参考。一起跟随小编过来看看吧
  • word内容 二进制相互转换word内容 二进制相互转换word内容 二进制相互转换,研究了好几天,被公司一MM 搞好了
  • 使用Java把Excel,Word,PDF,PPT,JPG,MP4等等文件转化为二进制格式存储到数据库中,然后在需要使用的地方再还原文件即可,这样方法相比普通上传下载文件来说比较安全很多 转化文件需要用到的jar包:...

              使用Java把Excel,Word,PDF,PPT,JPG,MP4等等文件转化为二进制格式存储到数据库中,然后在需要使用的地方再还原文件即可,这样方法相比普通上传下载文件来说比较安全很多

    转化文件需要用到的jar包:https://download.csdn.net/download/zxwu_1993/12058241

    本地测试文件

    存到数据库后的效果图

    文件恢复

     

     数据库结构信息

    -- Create table
    create table T_AUDIT_FILE
    (
      id          VARCHAR2(50) not null,
      fileid      VARCHAR2(50),
      filename    VARCHAR2(200),
      filecontent BLOB,
      filesize    INTEGER,
      suffix      VARCHAR2(50)
    )
    
    
    -- Add comments to the table 
    comment on table T_AUDIT_FILE
      is '文件表';
    -- Add comments to the columns 
    comment on column T_AUDIT_FILE.id
      is 'id';
    comment on column T_AUDIT_FILE.fileid
      is '文件编号';
    comment on column T_AUDIT_FILE.filename
      is '文件名称';
    comment on column T_AUDIT_FILE.filecontent
      is '文件内容';
    comment on column T_AUDIT_FILE.filesize
      is '文件大小';
    comment on column T_AUDIT_FILE.suffix
      is '文件后缀';
    -- Create/Recreate primary, unique and foreign key constraints 
    alter table T_AUDIT_FILE
      add constraint PK_T_AUDIT_FILE primary key (ID)

    具体实现代码如下

    数据库连接类

    import java.sql.Connection;
    
    import java.sql.DriverManager;
    
    public class DBConnection {
    
    	public static Connection getDBConnection() throws Exception {
    
    		Connection con = null;
    		String driver = "oracle.jdbc.driver.OracleDriver";
    		String url = "jdbc:oracle:thin:@127.0.0.1:1521/orcl";
    		String user = "ceshi";
    		String password = "Ceshi_0123";
    		Class.forName(driver);
    		con = DriverManager.getConnection(url, user, password);
    		return con;
    
    	}
    
    	public static void main(String[] args) throws Exception {
    		getDBConnection();
    		System.out.println("连接成功!");
    	}
    }

    文件转化二进制并存储到数据库的核心实现类

    import java.io.File;
    import java.io.FileInputStream;
    import java.io.InputStream;
    import java.io.OutputStream;
    import java.sql.Blob;
    import java.sql.CallableStatement;
    import java.sql.Connection;
    import java.sql.ResultSet;
    import java.sql.SQLException;
    import java.sql.Statement;
    import java.util.ArrayList;
    import java.util.Arrays;
    import java.util.UUID;
    
    
    import oracle.sql.BLOB;
    
    @SuppressWarnings("deprecation")
    public class Bolb_test {
    
    	public static void main(String[] args) throws SQLException {
    		ArrayList<String> listFileName = new ArrayList<String>();
    		getAllFileName("D:\\pdf\\", listFileName);
    		daor(listFileName);
    	}
    
    	public static void daor(ArrayList<String> listFileName) throws SQLException {
    		Connection con = null;
    		long start = System.currentTimeMillis(); // count runtime
    		CallableStatement pstmt = null;
    		InputStream fin = null;
    		OutputStream outStream = null;
    		for (String path : listFileName) {
    			File file = new File(path);
    			try {
    				con = DBConnection.getDBConnection();
    				con.setAutoCommit(false);
    				String sql = "insert into T_AUDIT_FILE values(?,?,?,?,?,?)";
    				// insert database
    				pstmt = con.prepareCall(sql);
    				String docid = "";
    				if (file.getName().indexOf(".", 1) == file.getName().lastIndexOf(".")) {
    					docid = file.getName().substring(0, file.getName().lastIndexOf("."));
    				} else {
    					docid = file.getName().substring(file.getName().indexOf(".", 1) + 1,
    							file.getName().lastIndexOf("."));
    				}
    				String suffix = file.getName().substring(file.getName().lastIndexOf(".") + 1);
    				String id = UUID.randomUUID().toString().replace("-", "");
    				pstmt.setString(1, id);
    				pstmt.setString(2, docid);
    				pstmt.setString(3, file.getName());
    				Blob doccontent = BLOB.empty_lob();
    				pstmt.setBlob(4, doccontent);
    				pstmt.setInt(5, (int) file.length());
    				pstmt.setString(6, suffix);
    				pstmt.execute();
    				Statement stmt = con.createStatement();
    				ResultSet rs = stmt
    						.executeQuery("select id,filecontent from T_AUDIT_FILE where id = '" + id + "' for update");
    				// get specially columns and rows for update
    				BLOB blob = null;
    				while (rs.next()) {
    					blob = (BLOB) rs.getBlob("filecontent");
    					outStream = blob.getBinaryOutputStream();
    					fin = new FileInputStream(file); // put file into stream
    
    					// BufferedInputStream bis = new BufferedInputStream(fin);
    					// byte[] b = new byte[(int) file.length()];
    
    					// byte[] b = new byte[blob.getBufferSize()];
    					int len = 0;
    					while ((len = fin.read()) != -1) {
    						outStream.write(len);
    					}
    					fin.close();
    					outStream.flush();
    					outStream.close();
    				}
    				String writeSql = "update T_AUDIT_FILE set filecontent = ? where id = ?";
    				java.sql.PreparedStatement ps = con.prepareStatement(writeSql);
    				ps.setBlob(1, blob);
    				ps.setString(2, id);
    				ResultSet rs1 = ps.executeQuery();
    				rs1.close();
    				con.commit();
    
    			} catch (Exception e) {
    				e.printStackTrace();
    			}
    		}
    		con.close();
    		long end = System.currentTimeMillis();
    		System.out.println(end - start);
    	}
    
    	public static void getAllFileName(String path, ArrayList<String> listFileName) {
    		File file = new File(path);
    		File[] files = file.listFiles();
    		String[] names = file.list();
    		if (names != null) {
    			String[] completNames = new String[names.length];
    			for (int i = 0; i < names.length; i++) {
    				completNames[i] = path + names[i];
    			}
    			listFileName.addAll(Arrays.asList(completNames));
    		}
    		for (File a : files) {
    			if (a.isDirectory()) {// 如果文件夹下有子文件夹,获取子文件夹下的所有文件全路径。
    				getAllFileName(a.getAbsolutePath() + "\\", listFileName);
    			}
    		}
    	}
    }

    文件恢复实现类

    import java.io.*;
    import java.sql.*;
    import oracle.sql.BLOB;
    
    @SuppressWarnings("deprecation")
    public class Getbolb_test {
    
    	public static void main(String[] args) throws SQLException {
    
    		Connection con = null;
    
    		long start = System.currentTimeMillis(); // count runtime
    
    		String path = "D:\\pdf\\文件恢复.jpg";
    
    		File file = new File(path);
    
    		try {
    
    			con = DBConnection.getDBConnection();
    
    			con.setAutoCommit(false);
    
    			Statement stmt = con.createStatement();
    
    			ResultSet rs = stmt.executeQuery("select id,filename,filecontent,filesize from T_AUDIT_FILE where id='4bde107e-9cc5-46a5-949c-65374a2bfe03'");
    
    			// get blob form your table
    
    			if (rs.next()) {
    				
    				int docsize = rs.getInt("filesize");
    				String docname = rs.getString("filename");
    				BLOB blob = (BLOB) rs.getBlob("filecontent");
    
    				// get word column
    
    				FileOutputStream output = new FileOutputStream(file);
    
    				// define a file output stream
    
    				InputStream input = blob.getBinaryStream();// put blob into input
    
    				//byte[] buffer = new byte[blob.getBufferSize()];
    				
    				byte[] buffer = new byte[docsize];
    
    				// if use 1024 it will lose some bytes
    
    				int len = 0;
    
    				while ((len = input.read(buffer)) != -1) {
    
    					// get all input stream into output file stream
    
    					output.write(buffer, 0, len);
    
    					input.close();
    
    					output.flush();
    
    					output.close();
    
    				}
    
    				System.out.print("\ndownload ok\n");
    
    			}
    
    		}
    
    		catch (Exception e) {
    
    			e.printStackTrace();
    
    		}
    
    		con.close();
    
    		long end = System.currentTimeMillis();
    
    		System.out.println(end - start);
    
    	}
    
    }
    

     

    展开全文
  • 通过freemarker 的word xml生成了word文件,现在想在下载的时候通过把模板获得的二进制流转变成html字符串再成然后变成pdf下载出来
  • //////二进制数据转换为word文件//////二进制数据///word文件名///word保存的相对路径publicstringByteConvertWord(byte[]data,stringfileName){stringsavePath=@"\SystemWord\"+FormatNowTime(2)+@"\";if(!System....
  • java二进制转换为图片

    2021-03-06 13:03:35
    我们经常会一个小的图片变成小一些的图片,利用 java 可以方便的实现,而 且实现了这个功能后就可以实现更强大的......BMP图二进制转换_IT/计算机_专业资料。BMP图格式 二进制转换 C#下 BMP 转换成二进制是比较...
  • I have a file in which its content is only 0's and 1'sI want to write a java program that convert each 8 bit of 0's and 1's to charor in other word, to convert the file content from binary to chars.Wh...
  • c的同事流量数据以二进制形式追加写入文件中,需要java端读取并解析,发送至kafka。 c的数据类型 Specifier Common Equivalent Signing Bits Bytes Minimum Value Maximum Value int8_t signed char ...
  • import java.util.Scanner;public class Test {public static String hexString2binaryString(String bString) {bString = bString.replace("", "");//去掉直接从word表格内复制出来的空格bString = bString.replace...
  • File ,byte[] , 二进制字符串之间互的多种方法汇集 /** * FileByte[] 方法一 * @param file * @return */ public static byte[] fileToBinArray(File file){ try { InputStream fis ...
  • 一个基于Java Socket协议之上文件传输的完整...基于Java Socket的二进制文件传输(包括图片,二进制文件,各种文档work,PDF)2.SwingWorker集合JProgressBar显示实时传输/接受完成的百分比3.其它一些Swing多线程编...
  • 使用Java将word转换成pdf文件

    热门讨论 2012-07-19 16:43:49
    大家可以试一试,使用Java将word转换成pdf文件
  • 弑天下首先你需要确定附件的类型及名称。然后下载很简单的,根据下载的请求返回response.addHeader ("content-type","application/RFC822");... filename=word,pdf");OutputStream os = null;try{os =...
  • 因为字节数组,除了写入文件或者以二进制的形式写入数据库以外,无法直接转为为字符串,因为字符串结尾有\0,当然肯定还有其他原因。下面提供几种Java中使用的方案:方案一:直接利用BigInteger的方法,应该是最简单...
  • 现在自己写了一个java的,以供参考。UTF-8 编码是一种被广泛应用的编码,这种编码致力于把全球的语言纳入一个统一的编码,目前已经几种亚洲语言纳入。UTF 代表 UCS Transformation Format.UTF-8 采用变长度字节来...
  • /** * 文件下载 *  * @param request * @param response * @param id * @throws Exception * @throws NumberFormatException ...private void downLoadFile(HttpServletRequest request, String id) ...throws Nu
  • java 文件格式二进制头文件校验

    千次阅读 2019-05-28 21:15:49
    java 文件格式二进制头文件校验
  • 十进制小数转二进制matlab代码压缩PGMA图像(Python) 提交说明:多媒体分配1 2019年1月30日到期,2019年2月12日到期 请在截止日期/时间之前直接在TRACS中(使用TRACS编辑器)或以文本/ MS-word / PDF附件的形式提交...
  • POI 文档

    2008-02-26 08:47:25
    POI是javaWord和Excel 文件操作的插件,这文档主要是教我们怎么使用POI插件对Word和Excel文件进行读写操作
  • import java.io.File;import java.io.FileInputStream;import java.io.FileOutputStream;import java.io.InputStream;import java.sql.Blob;import java.sql.Connection;import java.sql.PreparedStatement;import j...
  • Docx4j将word中的图片转换为二进制流1、findImageByIndex以及PICTURE_XPATH_2是什么可看上一篇博客public byte[] changeImageToByte(int index) throws Exception { Object inlineObj = findImageByIndex(PICTURE_...
  • DWORD WORD到INT的转换

    2021-03-09 04:28:17
    最近在做一个有关TCP/TP通信的消息解析,涉及到了这方面的...DWORDWORD: 无符号双字节整形(字,16位)DWORD:无符号四字节整形 (双字,32位)Byte:8位解析方式采用Java位操作来实现(采用大端方式,故先传递高位,则接...
  • } } } 2:iText把解析出来的数据填入word public class CreateWordDemo { public void createDocContext(String file) throws DocumentException, IOException { // 设置纸张大小 Document document =...
  • java转word实现

    2010-11-28 13:29:21
    Java生成word的资料,包括word的标题,在文档中生成表格。
  • 这个插件会把resources目录下的文本文件进行转码,但它无法正确的识别哪些是文本文件,因而会错误的不需要进行转码的二进制文件也进行转码,导致这些二进制文件无法打开。 解决的方法是在pom.xml中的maven-...

空空如也

空空如也

1 2 3 4 5 ... 20
收藏数 33,951
精华内容 13,580
关键字:

java将word转二进制

java 订阅