• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Can't find the file I created

 
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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!
 
author
Posts: 51
Android Java
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Brian Wong
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am using Windows Vista. Where is the data/data/ directory likely located?

Thanks!
 
author
Posts: 5856
7
Android Eclipse IDE Ubuntu
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The file is not anywhere in your Windows environment. If you are using the emulator, it is on the emulator's virtual disk.
 
Brian Wong
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 5856
7
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Ranch Hand
Posts: 252
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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

 
Dave MacLean
author
Posts: 51
Android Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
reply
    Bookmark Topic Watch Topic
  • New Topic