0
 file = new File(getFilesDir(), "data.txt");
 try {
   FileOutputStream fos = openFileOutput(fileName, Context.MODE_APPEND);
   fos.write(data.getBytes());
   fos.close();
 } catch (IOException e) {
   e.printStackTrace();
 }

Is there a way to export this file so I can have access to it? I don't have a SD-card available btw.

Thomas Böhm
  • 1,456
  • 1
  • 15
  • 27
JoSem
  • 309
  • 3
  • 14
  • It should be somewhere if you created it am I right – Tomm Oct 27 '17 at 08:57
  • You want to read the contents of the file? – Vüsal Oct 27 '17 at 08:59
  • @Vusal I want to export it outside the phone? How do I access it? – JoSem Oct 27 '17 at 09:01
  • 1
    @JoSem It is unclear what you are trying to achieve. If you have no SD card, you can either write to the local storage (which isn't what you want) or use some cloud- or network service. For the latter, I am sure there are some tutorials covering e.g. google drive, dropbox, owncloud,... – Turing85 Oct 27 '17 at 09:03
  • @Turing85 How is it unclear? lol. I want to export the file to my computer. Right now I can only read from it within the app. – JoSem Oct 27 '17 at 09:07
  • Just now did you actually mention that you wish to export the file to your PC (that was unclear up until now). You did not specify HOW you want to transfer the file. Do you want to send it via BlueTooth? USB Connection? A network share? – Turing85 Oct 27 '17 at 09:12
  • Sorry, the thing is that I have a txtfile that collects sensordata, and I need that textfile to format it. Right now I have no sd-card on my phone, and I've tried internal storage, but then I can't find the textfile. What are my options? thanks for your time – JoSem Oct 27 '17 at 09:15

2 Answers2

1
File file = new File(Environment.getExternalStorageDirectory()+"/Download/", "yourFile.extension");

This is for downloads directory.

Then to open your file

Intent myIntent = new Intent(Intent.ACTION_VIEW);
myIntent.setData(Uri.fromFile(file));
Intent j = Intent.createChooser(myIntent, "Choose an application to open with:");
startActivity(j);
Muhammad Saad Rafique
  • 3,158
  • 1
  • 13
  • 21
0

If you want to get your application path use getFilesDir() which will give you path /data/data/<your package>/files

So, you can find your file using android file manager in above mentioned directory.

From getFilesDir()

Vüsal
  • 2,580
  • 1
  • 12
  • 31
  • Yes, but I can't find the folder on my phone for some reason. I just want the textfile exported so I can format it. Is that possible? – JoSem Oct 27 '17 at 09:08
  • Try to use `getExternalFilesDir()` method. [Example](https://stackoverflow.com/a/43052803/4213803) – Vüsal Oct 27 '17 at 09:20
  • Isn't external storage explicitly for SD-memory? I don't have a sd-card – JoSem Oct 27 '17 at 09:27