0
我只有一個doc文件的代碼。我需要將文件夾中的多個doc文件轉換爲相應的文本文件。如何將一個文件夾中的多個doc文件轉換爲使用java的文本文件
碼單doc文件轉換爲文本文件:
import java.io.*;
import org.apache.poi.xwpf.extractor.XWPFWordExtractor;
import org.apache.poi.xwpf.usermodel.XWPFDocument;
public class ReadDocFile {
public static void main(String[] args) {
File file = null;
try {
// Read the Doc/DOCx file
file = new File("document");
FileInputStream fis = new FileInputStream(file.getAbsolutePath());
XWPFDocument doc = new XWPFDocument(fis);
XWPFWordExtractor ex = new XWPFWordExtractor(doc);
String text = ex.getText();
//write the text in txt file
File fil = new File("D:\\wordtotextoutput\\java1new.txt");
Writer output = new BufferedWriter(new FileWriter(fil));
output.write(text);
output.close();
} catch (Exception exep) {
}
}
}
嗨avempace你可以給這個完整的場景代碼它會幫助我很多iam java初學者所以只有 – user3437426