Saturday, February 5, 2022

Android - Return textfile content from asset

 // Return TextFile Contents from Asset

    private String GetAssetTextFile(String FILE_NAME){

        BufferedReader reader;

        finalContents = "";

        try{

            final InputStream file = getAssets().open(FILE_NAME);

            reader = new BufferedReader(new InputStreamReader(file));

            String lineTextHolder = reader.readLine();


            while(lineTextHolder != null){

                allTextHolder += lineTextHolder + "\n";

                lineTextHolder = reader.readLine();

            }


        } catch(IOException ioe){

            ioe.printStackTrace();

            allTextHolder = "";

        }

        finalContents = allTextHolder;

        return finalContents;

    }

No comments:

Post a Comment