Note that there are some explanatory texts on larger screens.

plurals
  1. POAndroid File Read and Write
    primarykey
    data
    text
    <p>I am new to Android programming and so kingly pardon me if this question sounds stupid. I want to read and write from a file in an Android Program. I am aware of how to do that in Java. </p> <p>Having read the documentation I wrote the following code. However I am unable to locate where this file is. According to the documentation it should be in folder data/data/package_name.</p> <p>I have Samsung Galaxy S2. I launched the application, then closed it. When I went looking for the file I could not find it. I looked in My Files/data. But there is no data folder inside this data folder. What am I doing wrong?</p> <p>Thank you for the help.</p> <p>Sources: 1. <a href="http://developer.android.com/training/basics/data-storage/files.html" rel="nofollow">http://developer.android.com/training/basics/data-storage/files.html</a> 2. <a href="http://www.vogella.com/articles/AndroidFileBasedPersistence/article.html#overview" rel="nofollow">http://www.vogella.com/articles/AndroidFileBasedPersistence/article.html#overview</a></p> <pre><code>public class MainActivity extends Activity { private void writeFileToInternalStorage() { String eol = System.getProperty("line.separator"); BufferedWriter writer = null; try { writer = new BufferedWriter(new OutputStreamWriter(openFileOutput("myfile.txt", MODE_WORLD_WRITEABLE))); writer.write("This is a test1." + eol); writer.write("This is a test2." + eol); } catch (Exception e) { e.printStackTrace(); } finally { if (writer != null) { try { writer.close(); } catch (IOException e) { e.printStackTrace(); } } } } @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); writeFileToInternalStorage(); } @Override public boolean onCreateOptionsMenu(Menu menu) { // Inflate the menu; this adds items to the action bar if it is present. getMenuInflater().inflate(R.menu.activity_main, menu); return true; } } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload