如何在Android中获取内部存储的绝对路径 [英] How to get absolute path of Internal Storage in Android

查看:1554
本文介绍了如何在Android中获取内部存储的绝对路径的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

内部存储路径

考虑上面的图片.它显示内部存储中的文件夹和文件.我的问题是我无法获取内部存储的绝对路径.我尝试使用

Consider the above picture. It shows the folders and file in internal storage. My problem is i am not able to get the absolute path of the internal storage. I Have tried using

字符串路径= getFilesDir().getAbsolutePath();

String path = getFilesDir().getAbsolutePath();

但这为我提供了应用存储的路径.我的目标是将文件从应用程序的私有存储备份到内部存储的顶部.而且我无法在Web上找到解决方案,也无法在堆栈溢出上找到解决方案.建议解决此问题的方法!

but it is giving me the path of my app storage. My objective is to backup a file from the private storage of my app to the top of internal storage. And i am unable to find a solution on web and neither on stack overflow. Suggest a solution to this problem!

推荐答案

Environment.getExternalStorageDirectory();

返回主要的共享/外部存储目录.

Return the primary shared/external storage directory.

注意:不要被外部"一词所混淆.这里.最好将此目录视为媒体/共享存储.它是一个文件系统,可以保存相对大量的数据,并且可以在所有应用程序之间共享(不强制执行权限).传统上,这是SD卡,但也可以在不同于受保护的内部存储的设备中实现为内置存储,并且可以作为文件系统安装在计算机上.

Note: don't be confused by the word "external" here. This directory can better be thought as media/shared storage. It is a filesystem that can hold a relatively large amount of data and that is shared across all applications (does not enforce permissions). Traditionally this is an SD card, but it may also be implemented as built-in storage in a device that is distinct from the protected internal storage and can be mounted as a filesystem on a computer.

File dir = Environment.getExternalStorageDirectory();
String path = dir.getAbsolutePath();

这篇关于如何在Android中获取内部存储的绝对路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆