0

I am trying to get access to a text file (log.txt) in a directory. All other questions on this topic refer to getting directories from the emulators internal storage.

My file structure is as such

>androidApp
->App 
-->Build
-->src
--->game_log
---->log.txt
--->Main
---->(Android app Code further)

Using new File(System.getProperty("user.dir) + "app\\src\\game_log\\log.txt").exists() gets me false.

Another thing I tried was System.getProperty("user.dir") but that yields me /.

Contextwrapper.getPath() gets me the path of the emulators storage.

Is the file structure of Android Studio different or I am using the wrong method to get the file from my project folder?

greatFritz
  • 165
  • 1
  • 14
  • 1
    If you want to include such a file in your APK, it should be placed in `assets` folder. See https://developer.android.com/reference/android/content/res/AssetManager and https://stackoverflow.com/questions/18302603/where-do-i-place-the-assets-folder-in-android-studio – Michael Butscher Apr 30 '19 at 02:17
  • @MichaelButscher So i'm using a text file to store current positions (ex: 1,2,3,4 \n 5,6,7,8) and I constantly need to update/delete contents after every game, take that text file and save it as another copy. I was playing around with assetmanager and i don't think I understand how to use the InputStreamreader to handle these operations. I am more familiar with FileReader – greatFritz Apr 30 '19 at 04:13
  • If you need to write a file look at https://developer.android.com/guide/topics/data/data-storage where the different storages are described. If you need the file to contain particular data at beginning you must check if the file is already in the storage, if not, read it from assets and write it to the storage. – Michael Butscher Apr 30 '19 at 04:22

0 Answers0