我正在尝试开发一个Java程序,从谷歌驱动器检索文件,并尝试重新上传它“是”。但是,在此过程中,它会丢失格式。
下面是我检索文件的方法:
private static java.io.File downloadFile(File uploadedFile)
throws IOException {
java.io.File downloadedFile = new java.io.File(parentDir, uploadedFile.getTitle() + UUID.randomUUID().toString());
try (OutputStream out = new FileOutputStream(downloadedFile)) {
drive.files().export(uploadedFile.getId(), "text/html").executeMediaAndDownloadTo(out);
}
return downloadedFile;
}下面是我更新文件的方法:
private static File updateFile(Drive service, String fileId, File file, java.io.File newContent) throws IOException {
FileContent mediaContent = new FileContent("text/html", newContent);
return service.files().update(fileId, file, mediaContent).execute();
}下面是我是如何组合这些方法的(相当虚拟的):
java.io.File downloaded = downloadFile(files.get(0));
updateFile(drive, files.get(0).getId(), files.get(0), downloaded);这是前后的文件:

这个过程是很好的,当我导出和重新导入的谷歌文件作为RTF或PDF,但我真的需要一个可编辑的格式。我错过了什么吗?
发布于 2018-06-26 13:14:20
这是预期的结果。PDF是确保格式得以保留的一种方式。对于Google Docs来说,就没那么多了。
https://stackoverflow.com/questions/51028857
复制相似问题