This week's book giveaway is in the Clojure forum.
We're giving away four copies of Clojure in Action and have Amit Rathore and Francis Avila on-line!
See this thread for details.
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Can't find the file I created

 
Brian Wong
Greenhorn
Posts: 7
  • 0
  • Mark post as helpful
  • send pies
  • 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!
 
Dave MacLean
author
Ranch Hand
Posts: 49
Android Java
  • 1
  • Mark post as helpful
  • send pies
  • 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
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am using Windows Vista. Where is the data/data/ directory likely located?

Thanks!
 
Peter Johnson
author
Bartender
Posts: 5852
7
Android Eclipse IDE Ubuntu
  • 1
  • Mark post as helpful
  • send pies
  • 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
  • 0
  • Mark post as helpful
  • send pies
  • 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
Bartender
Posts: 5852
7
Android Eclipse IDE Ubuntu
  • 0
  • Mark post as helpful
  • send pies
  • 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.
 
Nidhi Sar
Ranch Hand
Posts: 252
Android Eclipse IDE Ubuntu
  • 0
  • Mark post as helpful
  • send pies
  • 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
Ranch Hand
Posts: 49
Android Java
  • 0
  • Mark post as helpful
  • send pies
  • 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
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic