我已经使用 android 中的 FileOutputStream
从 HttpConnection
下载了一个文件,现在它被写入手机内存中的路径,就像我在 File Explorer 中找到的一样
/data/data/com.example.packagename/files/123.ics
现在,我想打开手机内存中的文件内容并将其读取到 UI。我试图通过使用 FileInputStream
来做到这一点,我只给出了带有扩展名的文件名来打开它,但我不确定如何提及内部存储器中文件的文件路径,因为它强制应用程序关闭。
有什么建议吗?
这就是我正在做的:
try
{
FileInputStream fileIn;
fileIn = openFileInput("123.ics");
InputStream in = null;
EditText Userid = (EditText) findViewById(R.id.user_id);
byte[] buffer = new byte[1024];
int len = 0;
while ( (len = in.read(buffer)) > 0 )
{
Userid.setText(fileIn.read(buffer, 0, len));
}
fileIn.close();
} catch (FileNotFoundException e)
{
e.printStackTrace();
}
catch (IOException e)
{
e.printStackTrace();
}
最佳答案
String filePath = context.getFilesDir().getAbsolutePath();//returns current directory.
File file = new File(filePath, fileName);
Similar post here
关于android - 如何从android中的手机内存中读取文件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2200545/