gpt4 book ai didi

java - 在android中获取 Activity 结果中的文件大小

转载 作者:太空狗 更新时间:2023-10-29 13:12:16 26 4
gpt4 key购买 nike

我有这段代码:

 public static final int RESULT_OK = -1;
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
switch (requestCode) {
case FILE_SELECT_CODE:
if (resultCode == RESULT_OK) {
// Get the Uri of the selected file
Uri fileUri = data.getData();
File F = new File(fileUri.getPath());
Log.d("File", "File Uri: " + fileUri.toString());
Intent intent = new Intent(getContext(),activity_file_sharing.class);
intent.putExtra("Filepath", fileUri.toString());
startActivity(intent);
}
break;
}
super.onActivityResult(requestCode, resultCode, data);
}

F.length() 总是返回 0 我需要将所选文件的大小传递给其他 Activity

谁能帮忙

最佳答案

请检查此链接:

how do I get file size of temp file in android?

试试这个:

File file = new File(selectedPath);
int file_size = Integer.parseInt(String.valueOf(file.length()/1024));

关于java - 在android中获取 Activity 结果中的文件大小,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38982814/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com