Pooja Dubey
Pooja Dubey

Reputation: 683

Use phone internal memory Android

I want to read a file from the phone internal memory.I have two memory in my device that is sdcard0 and sdcard1.sdcard1 is phone internal memory.So my file is in the phone internal memory . It's path is /storage/sdcard1/Android/New_Data.xml.So is this right way to access or not Please suggest me what i have do for this

Code

File file=new File("/storage/sdcard1/Android/New_Data.xml");
        if (file.exists()) {

        }else{

        }

This is working fine but i want to know is this a right way or not

Upvotes: 2

Views: 2839

Answers (3)

Kalai.G
Kalai.G

Reputation: 1610

Try getDir().

Refer Android getting external storage Absolute Path

File getdirectory = context.getDir("Samplefolder", Context.MODE_PRIVATE); 
if(!getdirectory .exists)
{
     getdirectory .mkdirs();
} 

Upvotes: 0

Developer
Developer

Reputation: 6350

See this might help you '

Read from here LINK TO UNDERSTAND

String FILENAME = "hello_file";
String string = "hello world!";

FileOutputStream fos = openFileOutput(FILENAME, Context.MODE_PRIVATE);
fos.write(string.getBytes());

fos.close();

Upvotes: 1

andy256
andy256

Reputation: 2881

The correct way to access Android storage is

Environment.getExternalStorageDirectory()

In your case, this would return /storage/sdcard1, and you could code

Environment.getExternalStorageDirectory().getAbsolutePath()+File.separator+"Android/New_Data.xml";

to get the pathname.

See the Environment reference.

Upvotes: 0

Related Questions