Creating a textfile and saving it to a particular location in android phone

2.7k Views Asked by At

I want to create a text file of the data received from bluetooth and then save it to a location from where it can be used by another application.

How can I solve this using code?

2

There are 2 best solutions below

0
On BEST ANSWER

Looks like dupe/related to StackOverflow: Saving file to phone in stead of SD-card

You should be able to use regular java File IO classes to save the actual data to the file.

4
On

Using FileWriter is one of the easiest ways:

File dir = Environment.getExternalStorageDirectory();
FileWriter writer = new FileWriter(new File(dir, "name.txt"));
writer.append("Hola\n");
writer.append("Hello\n");
writer.append("Etc...\n");
writer.flush();
writer.close();

This will save the file to the SDCard directory, which is accessible by other applications. Make sure to include the WRITE_EXTERNAL_STORAGE permission to your Manifest file.