Почему после загрузки текстового файла из мобильного хранилища в файл на диске Google с нулевым байтом на диске Google?
Мой код:
private void create_file_in_folder(final DriveId driveId) {
Drive.DriveApi.newDriveContents(mGoogleApiClient).setResultCallback(new ResultCallback<DriveApi.DriveContentsResult>() {
@Override public void onResult(@NonNull DriveApi.DriveContentsResult driveContentsResult) {
if (!driveContentsResult.getStatus().isSuccess()) {
Log.e(TAG, "U AR A MORON! Error while trying to create new file contents");
return;
}
OutputStream outputStream = driveContentsResult.getDriveContents().getOutputStream();
final File theFile = new File("/storage/emulated/0/notepad/note.txt");
try {
FileInputStream fileInputStream = new FileInputStream(theFile);
byte[] buffer = new byte[2048];
int bytesRead;
while ((bytesRead = fileInputStream.read(buffer)) != -1) {
outputStream.write(buffer, 0, bytesRead);
}
} catch (IOException e1) {
Log.i(TAG, "U AR A MORON! Unable to write file contents.");
}
MetadataChangeSet changeSet = new MetadataChangeSet.Builder().setTitle(theFile.getName()).setMimeType("text/plain").setStarred(false).build();
DriveFolder folder = driveId.asDriveFolder();
folder.createFile(mGoogleApiClient, changeSet, driveContentsResult.getDriveContents())
.setResultCallback(new ResultCallback<DriveFolder.DriveFileResult>() {
@Override public void onResult(@NonNull DriveFolder.DriveFileResult driveFileResult) {
if (!driveFileResult.getStatus().isSuccess()) {
Log.e(TAG, "U AR A MORON! Error while trying to create the file");
return;
}
Log.v(TAG, "Created a file: " + driveFileResult.getDriveFile().getDriveId());
}
});
}
});
}