views:

1291

answers:

3

I have downloaded a file from HttpConnection using the FileOutputStream in android and now its being written in phone's internal memory on path as i found it in File Explorer

/data/data/com.example.packagename/files/123.ics

Now, I want to open & read the file content from phone's internal memory to UI. I tried to do it by using the FileInputStream, I have given just filename with extension to open it but I am not sure how to mention the file path for file in internal memory,as it forces the application to close.

Any suggestions?

A: 

If the file is where you say it is, and your application is com.example.packagename, then calling openFileInput("123.ics"); will return you a FileInputStream on the file in question.

Or, call getFilesDir() to get a File object pointing to /data/data/com.example.packagename/files, and work from there.

CommonsWare
I was trying to do it in same way, but its not working
rob
can you see problem in this, sorry might be its not readable
rob
i am running out of character `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 ( (len1 = in.read(buffer)) > 0 )` `{` `Userid.setText(fileIn.read(buffer, 0, len1));`}` `fileIn.close();` `} catch (FileNotFoundException e)` `{` `e.printStackTrace();` `} catch (IOException e) {` `e.printStackTrace();` `}`
rob
@rob, edit your original question to add this info, instead of posting it in comments. Also, add your stacktrace.
mbaird
@mbaird, How can i add stacktrace?
rob
still not working, anybody can find out problem
rob
Why there is a silence, i am stuck in it. any suggestions?
rob
A: 

This is what i am doing

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(); }

rob
A: 

@rob where are you initializing InputStream? as from your code I can see that it is set to null.

Waqas