This week's book giveaways are in the Java EE and JavaScript forums.
We're giving away four copies each of The Java EE 7 Tutorial Volume 1 or Volume 2(winners choice) and jQuery UI in Action and have the authors on-line!
See this thread and this one for details.
The moose likes Android and the fly likes Can't find the file I created Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Mobile » Android
Bookmark "Can Watch "Can New topic
Author

Can't find the file I created

Brian Wong
Greenhorn

Joined: May 14, 2011
Posts: 7
I can't seem to find the file I created. What is wrong?



It's a very simple class with only one function, creating a file called "myfile.txt". But I can't find that file. Please help!
Dave MacLean
author
Ranch Hand

Joined: May 10, 2011
Posts: 49

The Context class has a method called getFilesDir() which will return the absolute path to where your file is being created. It is probably under /data/data somewhere but could be device-dependent so it's best to rely on that method call to find where it is.

- dave


Dave MacLean our book (Pro Android 4)
Brian Wong
Greenhorn

Joined: May 14, 2011
Posts: 7
I am using Windows Vista. Where is the data/data/ directory likely located?

Thanks!
Peter Johnson
author
Bartender

Joined: May 14, 2008
Posts: 5823
    
    7

The file is not anywhere in your Windows environment. If you are using the emulator, it is on the emulator's virtual disk.


JBoss In Action
Brian Wong
Greenhorn

Joined: May 14, 2011
Posts: 7
Can you believe what kind of newb I am? Thanks!!
So in an actual Android phone, whicj directory will this txt file be at?
Peter Johnson
author
Bartender

Joined: May 14, 2008
Posts: 5823
    
    7

Hmm, I should know this (I went through this exercise), but I'm away from home and don't have access to my notes. Try printing to the log the File.getAbsolutePath() - that will tell yo exactly where it is located.

By the way, my code checks to the existence of an SD card, and if one is there, I place my data file there. Makes it much easier to find, and I can always back it up, edit it, etc.
Nidhi Sar
Ranch Hand

Joined: Oct 19, 2009
Posts: 252

Brian Wong wrote:So in an actual Android phone, whicj directory will this txt file be at?


As Dave said, it is device dependent.
On my Atrix & Driod it would be /data/data/com.example.creatingfile/files


"A problem well stated is a problem half solved.” - Charles F. Kettering
SCJP 6, OCPJWCD
Dave MacLean
author
Ranch Hand

Joined: May 10, 2011
Posts: 49

A common pattern for where the files go is /data/data/your_package_name_here/files. If you're running your app on the emulator, you can use the FileExplorer within the DDMS perspective of Eclipse to navigate there. Or you can use "adb shell" from the command line of your computer to get a shell on the emulated device, then use basic Unix commands to cd to that directory. But knowing where the file is doesn't mean other apps can read it from there. Permissions are very strict within /data/data and files there are really just for the app that created them in the first place. As long as you continue to use the same filenames in your app, you should really care where the files go. Unless of course you want to create large files or files you want to share. Then you should definitely consider using the SD card instead. Even here though, you should use a method such as Environment.getExternalStorageDirectory() or Context.getExternalFilesDir(String type) to locate (and/or create) the appropriate directory in which to write your files.

- dave
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Can't find the file I created