Android 获取路径

Android

//   /data/data/包名/files
context.getFilesDir();   
//   /data/data/包名/cache
context.getCacheDir();    //这两个文件夹下的内容会随着app卸载而删除
//   /storage/emulated/0
Environment.getExternalStorageDirectory();
//   /storage/emulated/0/DCIM, 另外还有MOVIE/MUSIC等很多种标准路径
Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DCIM);    
//   /storage/emulated/0/Android/data/packname/files 
getExternalFilesDir(“”).getAbsolutePath()
//   /storage/emulated/0/Android/data/packname/cache
getExternalCacheDir().getAbsolutePath() 
//  遍历存储路径(有sd卡会额外打印)
File[] files;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
    files = getExternalFilesDirs(Environment.MEDIA_MOUNTED);
    for(File file:files){
        Log.e("main",file);
    }
}

ReactNative

借助第三方库react-native-fs实现

yarn add react-native-fs  //或者npm install react-native-fs --save
react-native link react-native-fs

使用

var RNFS = require('react-native-fs');
//   undefined
console.log('MainBundlePath',RNFS.MainBundlePath)
//   /data/data/com.rn_test_demo/cache
console.log('CachesDirectoryPath',RNFS.CachesDirectoryPath)
//   /data/data/com.rn_test_demo/files
console.log('DocumentDirectoryPath',RNFS.DocumentDirectoryPath)
//   /data/data/com.rn_test_demo/cache
console.log('TemporaryDirectoryPath',RNFS.TemporaryDirectoryPath)
//   undefined
console.log('LibraryDirectoryPath',RNFS.LibraryDirectoryPath)
//   /storage/emulated/0/Android/data/com.rn_test_demo/files
console.log('ExternalDirectoryPath',RNFS.ExternalDirectoryPath)
//  /storage/emulated/0
console.log('ExternalStorageDirectoryPath',RNFS.ExternalStorageDirectoryPath)
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值