Yeah, that's correct...
Here is a function in a project of mine that saves GPS coordinates to file
(full source will be posted soon...)
- void saveToFile() {
- //println("Saving GPS");
- String taggedLocation = tagLocation.getText() + ".3gp";
- String currLat = nf(currentLatitude, 2, 4);
- String currLon = nf(currentLongitude, 2, 4);
- try {
- BufferedWriter writer = new BufferedWriter(new FileWriter("//sdcard//SonicDrift//SavedLocations.txt", true));
- writer.write(taggedLocation);
- writer.write("\n");
- writer.write(currLat);
- writer.write("\n");
- writer.write(currLon);
- writer.write("\n");
- writer.flush();
- writer.close();
- println("Saved new file " + taggedLocation);
- }
- catch (IOException e) {
- println("Saving Error... ");
- }
- }
And in my setup() I do this to check that the directory exists on my SD Card...
- // Create Directory
- try{
- dirName = "//sdcard//SonicDrift";
- File newFile = new File(dirName);
- newFile.mkdirs();
- if(newFile.exists()) {
- println("Directory Exists...");
- if(newFile.isDirectory()) {
- println("isDirectory = true...");
- } else println("isDirectory = false...");
- } else {
- println("Directory Doesn't Exist...");
- }
- }
- catch(Exception e) {
- println("Exception creating folder... ");
- //e.printStackTrace();
- }
All of this code is taken from other examples on the forum here... there are quite a few threads about reading/writing...