How to write text to a file on external storage on android?
<p>Writing some text to a file on an android device seems to be a major endeavor. Starting from <a href="https://stackoverflow.com/questions/14376807/how-to-read-write-string-from-a-file-in-android">an answer given here</a> I have implemented the following code into my single 'Hello-World' activity: </p>

<pre><code>try {
    OutputStreamWriter outputStreamWriter = new OutputStreamWriter(this.openFileOutput("config.txt", Context.MODE_PRIVATE));
    outputStreamWriter.write("lalala");
    outputStreamWriter.close();
} catch (IOException e) {
    Log.e("Exception", "File write failed: " + e.toString());
}
</code></pre>

<p>which does not throw an exception, but seems to work. But is there a way to 'see' the file created with the <code>File Manager</code> on android? The code snippet seems to write to a 'secret' location on the android file system related to the application itself (governed by using <code>this.openFileOutput</code>).</p>

<p>Consulting different google-links (<a href="https://stackoverflow.com/questions/13779256/how-do-i-write-to-a-txt-file-in-android">this</a>  <a href="https://developer.android.com/reference/android/content/Context.html#openFileOutput%28java.lang.String,%20int%29" rel="nofollow noreferrer">and this</a> <a href="https://stackoverflow.com/questions/3625837/android-what-is-wrong-with-openfileoutput">and this</a>) I come up with the following code: </p>

<pre><code>File file = new File(this.getExternalFilesDir("temp"), "testfile.txt");
FileOutputStream fileOutput = openFileOutput(file.getName(), Context.MODE_WORLD_WRITEABLE);
fileOutput.write("lalala");
fileOutput.close();
</code></pre>

<p>which throws an error </p>

<pre><code>Error:(55, 19) error: no suitable method found for write(String) method FileOutputStream.write(int) is not applicable (actual argument String cannot be converted to int by method invocation conversion) method FileOutputStream.write(byte[],int,int) is not applicable (actual and formal argument lists differ in length) method OutputStream.write(int) is not applicable (actual argument String cannot be converted to int by method invocation conversion) method OutputStream.write(byte[],int,int) is not applicable (actual and formal argument lists differ in length) method OutputStream.write(byte[]) is not applicable (actual argument String cannot be converted to byte[] by method invocation conversion)
</code></pre>

<p>So how to do this right? </p>

<p>As a side note: This is for debugging/educational purposes only and not intended to be part of a final app! </p>

<p>To be clear: I want to create a file inside the <code>temp</code> directory I can see with a FileManager (the <code>temp</code> directory is on the same level as <code>My Documents</code>
, <code>Music</code>, <code>DCIM</code>, <code>Download</code> and the like...)</p>