A
A
aeaeae12021-05-08 02:56:08
Java
aeaeae1, 2021-05-08 02:56:08

How to read a file into a Java array?

There is a file in the asset folder. How to read it into a string array? Here is my code, how to specify path to asset folder?

ArrayList<String> list = new ArrayList<>();
        try (Scanner scan = new Scanner(new File("slova.txt"))) {
            while (scan.hasNextLine()) {
                list.add(scan.nextLine());
            }
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        }

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Denis Zagaevsky, 2021-05-08
@zagayevskiy

You need to use AssetManager. You can get it using the Context::getAssets method. The manager has an open method, where you can pass the path relative to the assets park.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question