Pankaj Kumar
Pankaj Kumar

Reputation: 67

How to save files(publically) on internal storage even if the external storage is available in android?

How to save files(publically) on internal storage even if the external storage is available in android?

I want to save files on the internal storage root path even if the external storage is mounted.

Upvotes: 0

Views: 89

Answers (1)

Nikhil Borad
Nikhil Borad

Reputation: 2085

suppose have a text file and save to local storage

public boolean saveFile(Context context, String myTextString){
    try {
        FileOutputStream fos = context.openFileOutput(getFilename(),Context.MODE_PRIVATE);
        Writer out = new OutputStreamWriter(fos);
        out.write(myTextString);
        out.close();
        return true;
    } catch (IOException e) {
        e.printStackTrace();
        return false;
    }
}

private String getFilename() {
    String filepath = Environment.getExternalStorageDirectory().getPath();
    File file = new File(filepath);
    if (!file.exists()) {
        file.mkdirs();
    }
    return (file.getAbsolutePath() + "/" + System.currentTimeMillis() + ".txt");

}

Hope this helps..

Upvotes: 1

Related Questions