Java 有没有办法在谷歌硬盘中写入和创建文本文件?
我正在编写一个简单的服务器,它将所有操作写入日志文件。立即写入在当前目录中创建的文件。有没有一种方法可以在谷歌硬盘中创建文件并写入,这样我就可以在远程位置看到服务器的操作 我当前的代码Java 有没有办法在谷歌硬盘中写入和创建文本文件?,java,Java,我正在编写一个简单的服务器,它将所有操作写入日志文件。立即写入在当前目录中创建的文件。有没有一种方法可以在谷歌硬盘中创建文件并写入,这样我就可以在远程位置看到服务器的操作 我当前的代码 void NewFile(String path, String data){ try{ File file =new File(path); //if file doesnt exists, then create it if(!file.exists
void NewFile(String path, String data){
try{
File file =new File(path);
//if file doesnt exists, then create it
if(!file.exists()){
file.createNewFile();
}
//true = append file
FileWriter fileWritter = new FileWriter(file.getName());
BufferedWriter bufferWritter = new BufferedWriter(fileWritter);
bufferWritter.write(data);
bufferWritter.write("\r" );
bufferWritter.write("\n" );
bufferWritter.close();
}catch(IOException e){
e.printStackTrace();
}
}
是的,你可以。查看GoogleDoc的API文档 Google Documents List API允许开发者创建、检索、, 更新,删除谷歌文档(包括但不限于文本 文档、电子表格、演示文稿和图纸)、文件和 收藏。它还提供了一些高级功能,如资源 归档、光学字符识别、翻译和修订 历史
您可以在 在这里,我只是从中粘贴了特定的代码段
//Create a new authorized API client
Drive service = new Drive.Builder(httpTransport, jsonFactory, credential).build();
//Insert a file
File body = new File();
body.setTitle("My document");
body.setDescription("A test document");
body.setMimeType("text/plain");
java.io.File fileContent = new java.io.File("document.txt");
FileContent mediaContent = new FileContent("text/plain", fileContent);
File file = service.files().insert(body, mediaContent).execute();
可能重复的