File System | Debug | 如何查看文件挂载的分区以及分区大小

说明:关键字

  • mount
  • /dev/block/xxx
  • /dev/block/by-name
  • {project}.xml

1. 查找块设备分区

adb shell 之后 mount 命令查看文件目录挂载的块设备分区(块设备节点)

C:\Users\calm.xia>adb shell
xxxproject:/ # mount
/dev/block/dm-3 on / type ext4 (ro,seclabel,relatime)
tmpfs on /dev type tmpfs (rw,seclabel,nosuid,relatime,size=1845504k,nr_inodes=461376,mode=755)
devpts on /dev/pts type devpts (rw,seclabel,relatime,mode=600,ptmxmode=000)
proc on /proc type proc (rw,relatime,gid=3009,hidepid=2)
sysfs on /sys type sysfs (rw,seclabel,relatime)
selinuxfs on /sys/fs/selinux type selinuxfs (rw,relatime)
tmpfs on /mnt type tmpfs (rw,seclabel,nosuid,nodev,noexec,relatime,size=1845504k,nr_inodes=461376,mode=755,gid=1000)
tmpfs on /apex type tmpfs (rw,seclabel,nosuid,nodev,noexec,relatime,size=1845504k,nr_inodes=461376,mode=755)
/dev/block/mmcblk0p38 on /metadata type ext4 (rw,seclabel,nosuid,nodev,noatime,errors=panic,data=ordered)
/dev/block/dm-4 on /vendor type ext4 (ro,seclabel,relatime)
/dev/block/dm-5 on /product type ext4 (ro,seclabel,relatime)
none on /dev/cg2_bpf type cgroup2 (rw,nosuid,nodev,noexec,relatime)
none on /dev/cpuctl type cgroup (rw,nosuid,nodev,noexec,relatime,cpu)
none on /acct type cgroup (rw,nosuid,nodev,noexec,relatime,cpuacct)
none on /dev/cpuset type cgroup (rw,nosuid,nodev,noexec,relatime,cpuset,noprefix,release_agent=/sbin/cpuset_release_agent)
none on /dev/memcg type cgroup (rw,nosuid,nodev,noexec,relatime,memory)
none on /dev/stune type cgroup (rw,nosuid,nodev,noexec,re

  • 0
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
在Android 10分区模式下,应用程序只能访问其专用目录中的文件。因此,要读写文件,您需要使用应用程序专用目录的路径。以下是使用File类读取和写入文件的步骤: 1. 获取应用程序专用目录的路径: ``` File directory = getContext().getFilesDir(); ``` 2. 创建一个File对象,指定要读取或写入的文件的路径: ``` File file = new File(directory, "myfile.txt"); ``` 3. 要读取文件,使用FileInputStream和BufferedInputStream类: ``` try { FileInputStream fileInputStream = new FileInputStream(file); BufferedInputStream bufferedInputStream = new BufferedInputStream(fileInputStream); byte[] buffer = new byte[1024]; int bytesRead = 0; while ((bytesRead = bufferedInputStream.read(buffer)) != -1) { String contents = new String(buffer, 0, bytesRead); // 处理文件内容 } bufferedInputStream.close(); fileInputStream.close(); } catch (IOException e) { e.printStackTrace(); } ``` 4. 要写入文件,使用FileOutputStream和BufferedOutputStream类: ``` try { FileOutputStream fileOutputStream = new FileOutputStream(file); BufferedOutputStream bufferedOutputStream = new BufferedOutputStream(fileOutputStream); String contents = "Hello world!"; bufferedOutputStream.write(contents.getBytes()); bufferedOutputStream.close(); fileOutputStream.close(); } catch (IOException e) { e.printStackTrace(); } ``` 请注意,您需要在AndroidManifest.xml文件中声明一个权限,在运行时请求该权限,以便您的应用程序可以读取和写入文件: ``` <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/> ``` 但是,在Android 10中,这个权限不再适用于访问应用程序专用目录。相反,您需要在AndroidManifest.xml文件中声明以下权限: ``` <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" /> <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /> ``` 并且您需要在代码中使用以下方法请求这些权限: ``` if (ContextCompat.checkSelfPermission(getContext(), Manifest.permission.READ_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED || ContextCompat.checkSelfPermission(getContext(), Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) { ActivityCompat.requestPermissions(getActivity(), new String[]{Manifest.permission.READ_EXTERNAL_STORAGE, Manifest.permission.WRITE_EXTERNAL_STORAGE}, 1); } ```

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值