0
代碼一個單獨的文件超過1個doc文件轉換的文件夾中到文本文件:如何使用java.canü修改此代碼
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 text file
File fil = new File("D:\\wordtotextoutput\\java1new.txt");
Writer output = new BufferedWriter(new FileWriter(fil));
output.write(text);
output.close();
} catch (Exception exep) {
}
}
}
什麼是FIS和DOC? – SoulRayder
你想對每個文件應用什麼規則?你想在文本文件中將它們一個接一個地追加在一起? 輸入文件也是文字嗎? – Squizer
您知道,您可以使用'java.io.renameTo' *移動*並重命名一個文件。 (雖然沒有我知道的簡單複製文件的機制,但使用'Runtime.exec'除外)。 –