我的项目需要从docx中读取一些数据,例如文本数据或表格数据。 这些需要读取的数据由我的项目经理指定。
如何准确读取这些数据?我应该将docx转换为xml并使用dom4j读取xml文件吗?如何使用Java进行转换?还是我们有一些更好的方法?
答案 0 :(得分:0)
您可以像这样使用Buffered Reader。
public boolean readWriteCSVFile()
{
boolean flag = false;
BufferedReader br = null;
try {
Path path = Paths.get("");
File file = new File(path.toAbsolutePath() + "//writeCSVFile.csv");
FileOutputStream fop = new FileOutputStream(file);
if (!file.exists()) {
file.createNewFile();
}
flag = true;
br = new BufferedReader(
new InputStreamReader(new FileInputStream(path.toAbsolutePath() + "//ReadCSV.csv")));
String line = "";
while ((line = br.readLine()) != null) {
String[] readLineSequence = line.split(",");
ReadWriteCSVFile rd = new ReadWriteCSVFile();
rd.writeCSVFile(line+"\r\n", fop);
for (String readLine : readLineSequence) {
System.out.print(readLine+",");
}
}
fop.close();
} catch (Exception ex) {
flag = false;
System.out.println(" Exception Occured while reading CSV file ");
ex.printStackTrace();
} finally {
try {
br.close();
} catch (Exception ex) {
System.out.println("Exception Inside finally : " + ex);
}
}
return flag;
}