JoSem
JoSem

Reputation: 309

How do I access the textfile I created?

 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.

Upvotes: 0

Views: 79

Answers (2)

Muhammad Saad Rafique
Muhammad Saad Rafique

Reputation: 3189

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

Upvotes: 1

Vüsal
Vüsal

Reputation: 2706

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

Upvotes: 0

Related Questions