rob*_*rob 3 memory android readfile
我已经从HttpConnection使用了FileOutputStreamandroid中下载了一个文件,现在它被写在路径中的电话内部存储器中,因为我发现它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();
}
Run Code Online (Sandbox Code Playgroud)
String filePath = context.getFilesDir().getAbsolutePath();//returns current directory.
File file = new File(filePath, fileName);
Similar post here
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
28076 次 |
| 最近记录: |