-1

Some questions about working with files on android. Is it possible to read files from project? Like from "src" directory. Also, how should I create files?

File file = new File("a.txt");
try {
    file.createNewFile();
} catch (IOException e) {
    e.printStackTrace();
}

Doesn't work here.

  • Possible duplicate of [Where do I place the 'assets' folder in Android Studio?](https://stackoverflow.com/questions/18302603/where-do-i-place-the-assets-folder-in-android-studio) – TheWanderer Oct 25 '18 at 20:09
  • you can't read files from src ,res , assets or any other folder that in your development environment.if you want access src files simply use their class names, if you want use res files simply use R class that compiled for this reason. and don't put your plain texts or any other files into your src dir. they must be in assets folder – nariman amani Oct 25 '18 at 20:24

1 Answers1

0

There are two types of storage facility available for file saving "internal" and "external" storage To create a file internally

File file = new File(context.getFilesDir(), filename);

getFilesDir() returns a File representing an internal directory.

To learn more please go through https://developer.android.com/training/data-storage/files

shb
  • 5,957
  • 2
  • 15
  • 32