我在安卓中使用FileOutputStream
从HttpConnection
下载了一个文件,现在它被写入到手机的内部存储器中,并且路径如下所示:
/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();
}