Android 如何获取文件的确切路径以将其转换为二进制文件?http://img4.imagetitan.com/img.php?image=11_logcat.png
经过多次搜索,我找到了文件的完整路径,但在将其转换为二进制文件时,出现了“NotFoundException”,请帮助 我的密码是 一, 二, } } //我在文件路径上遇到错误 //编写getGalleryDetails的CommonHelper类 三, Log.e(“byte”,bytes.toString()); 输出=空Android 如何获取文件的确切路径以将其转换为二进制文件?http://img4.imagetitan.com/img.php?image=11_logcat.png,android,Android,经过多次搜索,我找到了文件的完整路径,但在将其转换为二进制文件时,出现了“NotFoundException”,请帮助 我的密码是 一, 二, } } //我在文件路径上遇到错误 //编写getGalleryDetails的CommonHelper类 三, Log.e(“byte”,bytes.toString()); 输出=空 } catch (FileNotFoundException e) { e.printStackTrace(); } finally {
} catch (FileNotFoundException e) {
e.printStackTrace();
} finally {
try {
inputStream.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
return bytes;
}
请查看标题中的上述logcate链接请帮助我…提前感谢
fullpath
什么是bytes=CommonHelper.getGalleryDetails(fullpath);}代码>?我在文件路径上遇到错误
。这是一个错误。请显示日志猫。我已经上传了日志猫。请查看greenapps。经过大量搜索,我找到了文件的完整路径。哪个文件?你能不能先解释一下这个代码应该做什么或者用户应该做什么?你仍然没有说出完整的路径是什么。你没有告诉我你犯了什么错误。你没有发布日志。
public void onActivityResult(int requestCode, int resultCode, Intent data) {
String displayName = null;
byte[] bytes = null;
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();
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));
}
} finally {
cursor.close();
}
} else if (uriString.startsWith("file://")) {
displayName = myFile.getName();
}
String Str = new String(path);
int endPortal=Str.indexOf("document/");
String fullpath=Str.substring(0,endPortal)+"document/"+displayName;
try {
bytes=CommonHelper.getGalleryDetails(fullpath); } catch
(FileNotFoundException e) { // TODO Auto-generated catch block
e.printStackTrace(); } Log.e("fileBinary:", bytes.toString());
Toast.makeText(getBaseContext(), "Binary" + bytes.toString(), 5000).show();
public static byte[] getGalleryDetails(String FilePath)
throws FileNotFoundException {
InputStream inputStream = null;
byte[] bytes = null;
try {
inputStream = new FileInputStream(FilePath);
byte[] buffer = new byte[2048];
int bytesRead;
ByteArrayOutputStream output = new ByteArrayOutputStream();
try {
while ((bytesRead = inputStream.read(buffer)) != -1) {
output.write(buffer, 0, bytesRead);
}
output.close();
} catch (IOException e) {
e.printStackTrace();
}
bytes = output.toByteArray();
} catch (FileNotFoundException e) {
e.printStackTrace();
} finally {
try {
inputStream.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
return bytes;
}