【发布时间】:2016-06-22 07:22:16
【问题描述】:
我正在尝试获取如下所示的 docx 文件
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (resultCode == MainActivity.RESULT_OK) {
if (resultCode == RESULT_OK) {
// Get the Uri of the selected file
Uri uri = data.getData();
String uriString = uri.toString();
File myFile = new File(uriString);
String path = myFile.getAbsolutePath();
filepath =path;
String displayName = null;
if (uriString.startsWith("content://")) {
Cursor cursor = null;
try {
cursor = this.getContentResolver().query(uri, null, null, null, null);
if (cursor != null && cursor.moveToFirst()) {
displayName = cursor.getString(cursor.getColumnIndex(OpenableColumns.DISPLAY_NAME));
txtFilename.setText(displayName);
filename = displayName;
}
} finally {
cursor.close();
}
} else if (uriString.startsWith("file://")) {
displayName = myFile.getName();
txtFilename.setText(displayName);
filename = displayName;
}
}
}
}
现在结果是:
路径:/content:/com.estrongs.files/storage/emulated/0/Download/Imp%20Values.docx
文件名:Imp Values.docx
现在如何将此文档转换为 base64?
提前致谢。
【问题讨论】:
-
我从未尝试过,但我认为您可以像这样将您的文档转换为 byte[]:stackoverflow.com/questions/6058003/… 然后使用 Base64.encodeToString(yourByteArray,Base64.默认)。但我读到一些东西,这会增加你的文件大小....
-
就我的理解来说,应该是把图片转成Base64吧.....
标签: android base64 document docx doc