在没有第三方库的Java中将RTF转换为Java中的DOCX文件
是否有任何方法可以将RTF格式的文件转换为DOCX格式,而没有第三方库,例如Aspose等。我尝试使用InputStream和outputStream,但会导致损坏的DOCX文件。
private static void convertToDoc() throws IOException {
String inputPath = "C:\\inputFile.rtf";
String OutputPath = "C:\\outputFile.docx";
File initialFile = new File(inputPath);
InputStream source = new FileInputStream(initialFile);
OutputStream target = new FileOutputStream(OutputPath);
byte[] buf = new byte[8192];
int length;
while ((length = source.read(buf)) > 0) {
target.write(buf, 0, length);
}
source.close();
target.close();
}
Is there any way to convert a file in rtf format to docx format without third party libraries such as aspose etc. I tried to use InputStream and OutputStream but it leads to a corrupted docx file.
private static void convertToDoc() throws IOException {
String inputPath = "C:\\inputFile.rtf";
String OutputPath = "C:\\outputFile.docx";
File initialFile = new File(inputPath);
InputStream source = new FileInputStream(initialFile);
OutputStream target = new FileOutputStream(OutputPath);
byte[] buf = new byte[8192];
int length;
while ((length = source.read(buf)) > 0) {
target.write(buf, 0, length);
}
source.close();
target.close();
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论