在android中从SD卡读取特定文件
如何从SD卡读取特定文件。我已通过DDMS将SD卡中的文件推入,我正试图通过这种方式读取它,但这给了我一个例外。有人能告诉我如何准确地指出那个档案吗 我的密码是这个在android中从SD卡读取特定文件,android,file,android-sdcard,Android,File,Android Sdcard,如何从SD卡读取特定文件。我已通过DDMS将SD卡中的文件推入,我正试图通过这种方式读取它,但这给了我一个例外。有人能告诉我如何准确地指出那个档案吗 我的密码是这个 String path = Environment.getExternalStorageDirectory().getAbsolutePath(); FileInputStream iStream = new FileInputStream(path); 您正在尝试读取目录。。。你需要的是文件!像这样做。。。然后,您可以根据需要
String path = Environment.getExternalStorageDirectory().getAbsolutePath();
FileInputStream iStream = new FileInputStream(path);
您正在尝试读取目录。。。你需要的是文件!像这样做。。。然后,您可以根据需要读取该文件
File dir = Environment.getExternalStorageDirectory();
File yourFile = new File(dir, "path/to/the/file/inside/the/sdcard.ext");
要从外部存储读取任何文件(在我的例子中是CSV),我们需要它的路径,一旦你有了路径,你就可以这样做
void readFileData(String path) throws FileNotFoundException
{
String[] data;
File file = new File(path);
if (file.exists())
{
BufferedReader br = new BufferedReader(new FileReader(file));
try
{
String csvLine;
while ((csvLine = br.readLine()) != null)
{
data=csvLine.split(",");
try
{
Toast.makeText(getApplicationContext(),data[0]+" "+data[1],Toast.LENGTH_SHORT).show();
}
catch (Exception e)
{
Log.e("Problem",e.toString());
}
}
}
catch (IOException ex)
{
throw new RuntimeException("Error in reading CSV file: "+ex);
}
}
else
{
Toast.makeText(getApplicationContext(),"file not exists",Toast.LENGTH_SHORT).show();
}
}
/*
csv file data
17IT1,GOOGLE
17IT2,AMAZON
17IT3,FACEBOOK*/
在我的应用程序中,有一个contactbackup.vcf文件存储在SD卡中。我怎样才能一个接一个地读取.vcf文件。@克里斯蒂安:嗨,请问有没有方法返回文件名?如果我不知道文件名@克里斯蒂安