0

I want to implement a "View" functionality in my app where the file is opened,but not actually saved to disk. How do i download the file, then open it without saving to disk?

(I've noticed that a lot of other apps that do this don't need the storage permissions to open files so they surely must not be saving it to disk right?)

Or should i create a temporary file and then delete it when i'm done with it?

Guest1997
  • 449
  • 8
  • 22

3 Answers3

0

You don't need a permission for saving a file in the internal files directory. That's what most apps do. If you don't want to do that, you can read the file to a String object, and process it from there. You can use Apache IOUtils.copy for that. Hereenter link description here is a stackoverflow question where it's described. You could have found that yourself by using Google.

Community
  • 1
  • 1
Christine
  • 5,441
  • 4
  • 37
  • 59
0

If your concern to secure that file, you can simply store that file into your app's internal memory as private file, No app can open that file without your app context. To store files in internal memory:

File theDir = context.getDir("theDir", Context.MODE_PRIVATE); 
File fileWithinThatDir = new File(theDir, "yourFile");
FileOutputStream out = new FileOutputStream(fileWithinThatDir);

to delete that file:

new File("PathOfThatFile").delete();
noman404
  • 856
  • 8
  • 22
0

Download the file to a ByteArrayOutputStream or directly to a byte array. That is all in memory.

greenapps
  • 10,799
  • 2
  • 13
  • 19