# How to write to file

**URL:** <https://discourse.processing.org/t/how-to-write-to-file/16096>\
**Category:** Processing for Android\
**Created:** [December 4, 2019, 2:17am UTC](https://discourse.processing.org/t/how-to-write-to-file/16096 "2019-12-04T02:17:16Z")\
**Posts on this page:** 1\
**Showing post:** 5

<div class="post-metadata">

**Author:** ![noel](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/noel/32/213_2.png) [@noel](https://discourse.processing.org/u/noel)\
**Post date:** [December 4, 2019, 8:16am UTC](https://discourse.processing.org/t/how-to-write-to-file/16096/5 "2019-12-04T08:16:25Z")

</div>

Here’s how to save strings in Android.

Be sure to give permission WRITE\_EXTERNAL\_STORAGE

```auto
import android.os.Environment;

void setup() {
  String[] holder = new String[3]; 
  holder[0] = "Just";
  holder[1] = "an";
  holder[2] = "example";
  // Folowing file name is the folder you save your text file in.
  // If it does not exist it will be created automatically
  String stringFolder = "MyStrings";
  // Folowing string is the name of your text file
  // Be sure to include extension.
  String textFile = "MyText.txt";
  saveMyText(stringFolder, textFile, holder);
}

void saveMyText(String sf, String tf, String[] sh) { 
  try { 
    String absolute_path = new String(Environment.getExternalStorageDirectory().getAbsolutePath()); 
    File file = new File(absolute_path+"/"+sf); 
    println(file);
    if (!file.exists()) { 
      boolean success = true; 
      success = file.mkdirs();
    } 
    saveStrings(file+"/"+tf, sh);
    println("File saved successfully.");
  } 
  catch (Exception e) { 
    println("Error while saving file: " + e);
  }
}  

```

---

_[View the full topic](https://discourse.processing.org/t/how-to-write-to-file/16096)._
