Java 如何将.doc文件读入字节[]数组?
如何从.doc或word文件中获取Java 如何将.doc文件读入字节[]数组?,java,Java,如何从.doc或word文件中获取字节[]值 我尝试使用输入流并将其转换为字节[],但当我将其写回.doc文件时,它将被损坏 有更好的方法吗?下面是ReadDoc/docx.java的代码:它将读取一个dox/docx文件并将其内容打印到控制台。你可以自己定制。要运行此程序,您需要apache的poi jar 这将程序可以给你字符串数组 import java.io.*; import org.apache.poi.hwpf.HWPFDocument; import org.apache.poi
字节[]
值
我尝试使用输入流并将其转换为字节[]
,但当我将其写回.doc文件时,它将被损坏
有更好的方法吗?下面是ReadDoc/docx.java的代码:它将读取一个dox/docx文件并将其内容打印到控制台。你可以自己定制。要运行此程序,您需要apache的poi jar 这将程序可以给你字符串数组
import java.io.*;
import org.apache.poi.hwpf.HWPFDocument;
import org.apache.poi.hwpf.extractor.WordExtractor;
public class ReadDocFile {
public static void main(String[] args) {
File file = null;
WordExtractor extractor = null ;
try {
file = new File("c:\\New.doc");
FileInputStream fis=new FileInputStream(file.getAbsolutePath());
HWPFDocument document=new HWPFDocument(fis);
extractor = new WordExtractor(document);
String [] fileData = extractor.getParagraphText();
for(int i=0;i<fileData.length;i++){
if(fileData[i] != null)
System.out.println(fileData[i]);
}
}
catch(Exception exep){}
}
}
import java.io.*;
导入org.apache.poi.hwpf.hwpf文档;
导入org.apache.poi.hwpf.extractor.WordExtractor;
公共类ReadDocFile{
公共静态void main(字符串[]args){
File=null;
WordExtractor-extractor=null;
试一试{
文件=新文件(“c:\\new.doc”);
FileInputStream fis=新的FileInputStream(file.getAbsolutePath());
HWPF文件=新的HWPF文件(fis);
提取器=新单词提取器(文档);
String[]fileData=extractor.getParagraphText();
对于(int i=0;ii)如果你做得正确,它会工作的。给我们看一些代码。它的副本可能会损坏,或者你尝试了,但它确实损坏了它?你能告诉我们在这个实现中需要哪些JAR及其版本吗?
File file = new File("filename");//filename should be with complete path
FileInputStream fis = new FileInputStream(file);
byte[] b = new byte[ (int) file.length()];
fis.read(b);