我想读和写一个文本文件,我上传到“一个驱动器”或“谷歌驱动器”的java。
BufferedReader bufferedReader;
String line;
URL url = new URL("https://docs.google.com/document/d/1JLRmW7eaXHyyoPdNCyNN7AHWzKWaAPWgL84sxHUB7dQ/edit");
bufferedReader = new BufferedReader(new InputStreamReader(url.openStream()));
while ((line = bufferedReader.readLine()) != null) {
System.out.println(line);
}对于这段代码,我只阅读了HTML文档,这对我没有什么帮助。在这个文本中有一些来自服务器的IP地址,我必须与客户端连接。请注意,我想从java程序访问此文件,而不是从android应用程序。根据我的研究,可用的google drive api不太适合java实现,因为它们是为android解决方案构建的。
发布于 2018-01-03 05:30:35
可用的google drive api不太适合java实现。
Google API支持Java。Android是Java,所以API (类,你需要调用的方法,等等)在这两个平台上都是一样的。
Drive API是Google API客户端库的一部分。下面是一个很好的概述:
一个包含设置说明的Developer's Guide和一些Examples。
drive-cmdline-sample项目将是一个很好的起点。有一个downloadFile方法,它看起来可以获取源文件:
/** Downloads a file using either resumable or direct media download. */
private static void downloadFile(boolean useDirectDownload, File uploadedFile)
throws IOException {
// create parent directory (if necessary)
java.io.File parentDir = new java.io.File(DIR_FOR_DOWNLOADS);
if (!parentDir.exists() && !parentDir.mkdirs()) {
throw new IOException("Unable to create parent directory");
}
OutputStream out = new FileOutputStream(new java.io.File(parentDir, uploadedFile.getTitle()));
MediaHttpDownloader downloader =
new MediaHttpDownloader(httpTransport, drive.getRequestFactory().getInitializer());
downloader.setDirectDownloadEnabled(useDirectDownload);
downloader.setProgressListener(new FileDownloadProgressListener());
downloader.download(new GenericUrl(uploadedFile.getDownloadUrl()), out);
}https://stackoverflow.com/questions/48065080
复制相似问题