views:

403

answers:

2

In Reference to this android file download problem

http://stackoverflow.com/questions/576513/android-download-binary-file-problems

Can anyone explain what does this line mean in the code

FileOutputStream f = new FileOutputStream(new File(root,"Video.mp4"));

And what does it mean by the parameter root within the File(). Do I need to specify the root path to save the file? if it is the case then how do we specify the root path in android ?

Regards

+2  A: 

The java.io.File(File, String) or java.io.File(String, String) are standard java constructors for Java. The first argument is just the parent directory path, while the second is the actual file name. If the file is in the current working directory or you know the full path as one string you can avoid the 2 argument constructors.

Since you are trying to download a file you can just acquire the file through a normal URL.openStream() to get an InputStream to get the contents of your downloaded file. For writing the data out you will follow the example you linked to to write the contents.

I'm unsure what the root variable was pointed to in the example. I'm not able to help you beyond this though since I have only gone through the first Hello, Android example myself.

shrub34
i am trying to download file in android emulator.So how can i give path? Is this the path in android memory ? I don't have SD card, do i need to have one to have the file on android app ?
rob
Rob, on its own the above code writes to whichever folder `root` is set to, as shrub34 notes. See the latest answers to your previous question about how to choose between internal storage and the SD card:http://stackoverflow.com/questions/2148570/can-i-download-file-without-using-the-phone-memory-instead-of-virtual-sd-card-in
Christopher
+2  A: 

And what does it mean by the parameter root within the File(). Do I need to specify the root path to save the file? if it is the case then how do we specify the root path in android?

The code snippet from the question you linked doesn't define the variable, but if the code is downloading a file to the device, I would assume that it's a path on the SD card. Environment.getExternalStorageDirectory() will give you the root path to the SD card. You'll also need to specify the WRITE_EXTERNAL_STORAGE permission in your manifest.

If you're working on the emulator, you can create a virtual SD card when you create the emulator image.

Erich Douglass
Can i do it without creating virtual SD Card. Is there any way to save the file in phone memory in internal memory?
rob