2

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

Pooja Dubey
  • 683
  • 2
  • 14
  • 34

3 Answers3

1

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();
Developer
  • 6,292
  • 19
  • 55
  • 115
0

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.

andy256
  • 2,821
  • 2
  • 13
  • 19
  • how will access please help me with complete path – Pooja Dubey Sep 19 '13 at 07:12
  • @PoojaDubey looks like you have a file on your external storage. try this `File file=new File(Environment.getExternalStorageDirectory().getAbsolutePath()+File.seperator+Android+File.seperator+New_Data.xml)` If its on external storage add permission in manifest. – Raghunandan Sep 19 '13 at 07:16
  • after what you said it is showing me R cannot be resolved to a variable error what i have to do now – Pooja Dubey Sep 19 '13 at 07:18
  • Suggest you post a new question with the details for the XML error. – andy256 Sep 19 '13 at 07:24
  • /storage/sdcard0/Android/New_Data.xml this path it is returning me but the i need /storage/sdcard1/Android/New_Data.xml – Pooja Dubey Sep 19 '13 at 07:29
0

Try getDir().

Refer Android getting external storage Absolute Path

File getdirectory = context.getDir("Samplefolder", Context.MODE_PRIVATE); 
if(!getdirectory .exists)
{
     getdirectory .mkdirs();
} 
Community
  • 1
  • 1
Kalai.G
  • 1,610
  • 13
  • 22