Android 路径:“/SD卡/";适用于所有设备?
我在我的应用程序中使用了此代码 它对所有设备都正常吗?它对所有设备都有效吗Android 路径:“/SD卡/";适用于所有设备?,android,android-sdcard,Android,Android Sdcard,我在我的应用程序中使用了此代码 它对所有设备都正常吗?它对所有设备都有效吗 String path= "/sdcard/.beta1/data/text/myfile.txt"; File myFile = new File(path); myFile.getParentFile().mkdirs(); myFile.createNewFile(); FileOutputStream fOut = new FileOutputStream(myFile); 我还尝试了Environment.g
String path= "/sdcard/.beta1/data/text/myfile.txt";
File myFile = new File(path);
myFile.getParentFile().mkdirs();
myFile.createNewFile();
FileOutputStream fOut = new FileOutputStream(myFile);
我还尝试了Environment.getExternalStorageDirectory().getPath()但是我不知道哪一个更好更稳定
所有设备都可以吗?所有设备都可以吗
String path= "/sdcard/.beta1/data/text/myfile.txt";
File myFile = new File(path);
myFile.getParentFile().mkdirs();
myFile.createNewFile();
FileOutputStream fOut = new FileOutputStream(myFile);
不。它不仅不能在所有设备上工作,而且不能在所有设备的所有用户上工作。大多数安卓设备支持多用户;不同的用户将有不同的和路径从不硬编码路径
使用、或处理外部存储上的文件。前两种方法的优点是不需要API级别19或更高级别的任何权限
所有设备都可以吗?所有设备都可以吗
String path= "/sdcard/.beta1/data/text/myfile.txt";
File myFile = new File(path);
myFile.getParentFile().mkdirs();
myFile.createNewFile();
FileOutputStream fOut = new FileOutputStream(myFile);
不。它不仅不能在所有设备上工作,而且不能在所有设备的所有用户上工作。大多数安卓设备支持多用户;不同的用户将有不同的和路径从不硬编码路径
使用、或处理外部存储上的文件。前两种方法的优点是不需要API级别19或更高级别的任何权限
所有设备都可以吗?所有设备都可以吗
String path= "/sdcard/.beta1/data/text/myfile.txt";
File myFile = new File(path);
myFile.getParentFile().mkdirs();
myFile.createNewFile();
FileOutputStream fOut = new FileOutputStream(myFile);
不。它不仅不能在所有设备上工作,而且不能在所有设备的所有用户上工作。大多数安卓设备支持多用户;不同的用户将有不同的和路径从不硬编码路径
使用、或处理外部存储上的文件。前两种方法的优点是不需要API级别19或更高级别的任何权限
所有设备都可以吗?所有设备都可以吗
String path= "/sdcard/.beta1/data/text/myfile.txt";
File myFile = new File(path);
myFile.getParentFile().mkdirs();
myFile.createNewFile();
FileOutputStream fOut = new FileOutputStream(myFile);
不。它不仅不能在所有设备上工作,而且不能在所有设备的所有用户上工作。大多数安卓设备支持多用户;不同的用户将有不同的和路径从不硬编码路径
使用、或处理外部存储上的文件。前两种方法的优点是不需要API级别19或更高级别的任何权限。要读取文件:
final File file = new File(Environment.getExternalStorageDirectory()
.getAbsolutePath(), filename);
文件名
它是一个字符串
变量
或者您也可以使用:
File sdCardDirectory = new File(Environment.getExternalStorageDirectory() + File.separator + "MyFolder/" + "MyFile.txt");
要读取文件,请执行以下操作:
final File file = new File(Environment.getExternalStorageDirectory()
.getAbsolutePath(), filename);
文件名
它是一个字符串
变量
或者您也可以使用:
File sdCardDirectory = new File(Environment.getExternalStorageDirectory() + File.separator + "MyFolder/" + "MyFile.txt");
要读取文件,请执行以下操作:
final File file = new File(Environment.getExternalStorageDirectory()
.getAbsolutePath(), filename);
文件名
它是一个字符串
变量
或者您也可以使用:
File sdCardDirectory = new File(Environment.getExternalStorageDirectory() + File.separator + "MyFolder/" + "MyFile.txt");
要读取文件,请执行以下操作:
final File file = new File(Environment.getExternalStorageDirectory()
.getAbsolutePath(), filename);
文件名
它是一个字符串
变量
或者您也可以使用:
File sdCardDirectory = new File(Environment.getExternalStorageDirectory() + File.separator + "MyFolder/" + "MyFile.txt");
使用Environment.getExternalStorageDirectory().getPath()代码>,我认为它更好…请告诉我如何使用它?在一些帖子中,我看到它有时返回内部存储的路径?当然,请查看我的回答使用Environment.getExternalStorageDirectory().getPath()代码>,我认为它更好…请告诉我如何使用它?在一些帖子中,我看到它有时返回内部存储的路径?当然,请查看我的回答使用Environment.getExternalStorageDirectory().getPath()代码>,我认为它更好…请告诉我如何使用它?在一些帖子中,我看到它有时返回内部存储的路径?当然,请查看我的回答使用Environment.getExternalStorageDirectory().getPath()代码>,我认为它更好…请告诉我如何使用它?在一些帖子中,我看到它有时返回内部存储的路径?当然,请检查我的回答OK谢谢,还有一个查询-'String path=Environment.getExternalStorageDirectory().getPath()+“/.beta/”;'与'path=“/sdcard/.beta/”;相同@阿玛:不要创建字符串。您需要一个文件
。使用File betaDir=new文件(Environment.getExternalStorageDirectory(),“.beta”)代码>。好的,谢谢,再来一个查询-'String path=Environment.getExternalStorageDirectory().getPath()+“/.beta/”;'与'path=“/sdcard/.beta/”;相同@阿玛:不要创建字符串。您需要一个文件
。使用File betaDir=new文件(Environment.getExternalStorageDirectory(),“.beta”)代码>。好的,谢谢,再来一个查询-'String path=Environment.getExternalStorageDirectory().getPath()+“/.beta/”;'与'path=“/sdcard/.beta/”;相同@阿玛:不要创建字符串。您需要一个文件
。使用File betaDir=new文件(Environment.getExternalStorageDirectory(),“.beta”)代码>。好的,谢谢,再来一个查询-'String path=Environment.getExternalStorageDirectory().getPath()+“/.beta/”;'与'path=“/sdcard/.beta/”;相同@阿玛:不要创建字符串。您需要一个文件
。使用File betaDir=new文件(Environment.getExternalStorageDirectory(),“.beta”)代码>。