0

I want to get a file which i saved in a specific directory on my phone. How can I find and get a ref to it so I can do with it something different like uploading to a server?

Thanks in advance.

Shiran

wojciii
  • 4,253
  • 1
  • 30
  • 39

2 Answers2

0
File f = new File("location");

Remember, if you're trying to access the sd card you need to set permissions. Then just handle the "file" in whatever way it is you're trying to do something.

If you're looking to use the SDCard check this post: Permission to write to the SD card

[Edit - Example]

String filenameToWrite = "Test.jpg"
try{
    File f = new File(Environment.getExternalStorageDirectory() + "/Photos/");
    if (f.exists()){
        File fileToWrite = new File(Environment.getExternalStorageDirectory() + "/Photos/" + filenameToWrite;
        // Do something to write file, save bitmap, save byte stream, etc.
    }
} catch(IOException e){
    Log.e("File", "Could not save file, error occured: " + e.toString());
}

Here's a few getting started tutorials to help you understand how to read and write files in java. This (apart from the 'path') is a java question, not an Android one.

Tutorials:

http://beginwithjava.blogspot.com/2011/04/java-file-save-and-file-load-objects.html

http://www.roseindia.net/java/beginners/java-write-to-file.shtml

Community
  • 1
  • 1
RyanInBinary
  • 1,533
  • 3
  • 19
  • 47
  • can u give an example how to write the location - let just say i have Pictures folder? Thanks alot!! – Talia Schwartz Aug 08 '12 at 12:31
  • 1
    if you have solved ur problem then you should `accept answer` if not then post ur Query – MAC Aug 08 '12 at 13:06
  • Not a problem. Please be sure to upvote if possible... and mark the question as answered so other's can learn from it. To mark it as answered, click the checkmark below the "0" that has the up/down arrows around it. To upvote, click the up arrow above the zero. Be sure to give Hades some love too. – RyanInBinary Aug 08 '12 at 13:07
0

Well where do you store your file?

Store the file in a specific area such as

Environment.getExternalStorageDirectory()

Then when you want to read it, just use the file name used and the path obtained from the above method.

Hades
  • 3,916
  • 3
  • 34
  • 74