openFileOutput() method vs FileOutputStream() constructor

Tags: ,



Why in Android one should use openFileOutput() method instead of FileOutputStream() constructor?

Would the mode type as a second param of openFileOutput() be the only “respectful” reason for all the cases?

FileOutputStream fos;
fos = openFileOutput("test.txt", Context.MODE_PRIVATE);
fos = new FileOutputStream("test.txt");

Answer

Would the mode type as a second param of openFileOutput() be the only “respectful” reason for all the cases?

Another difference is that openFileOutputStream opens / creates a file in the the device’s “internal” storage. By contrast FileOutputStream allows use of both internal and external storage.

A third difference is that openFileOutputStream writes files in the context of the current application, while FileOutputStream can write in any context … modulo possible permissions issues.

(Both versions can open files in append mode. That is not a point of difference.)

Reference:



Source: stackoverflow