How can I read a text file from the SD card in Android?

后端 未结 6 2215
太阳男子
太阳男子 2020-11-22 16:42

I am new to Android development.

I need to read a text file from the SD card and display that text file. Is there any way to view a text file directly in Android or

6条回答
  •  难免孤独
    2020-11-22 16:57

    Beware: some phones have 2 sdcards , an internal fixed one and a removable card. You can find the name of the last one via a standard app:"Mijn Bestanden" ( in English: "MyFiles" ? ) When I open this app (item:all files) the path of the open folder is "/sdcard" ,scrolling down there is an entry "external-sd" , clicking this opens the folder "/sdcard/external_sd/" . Suppose I want to open a text-file "MyBooks.txt" I would use something as :

       String Filename = "/mnt/sdcard/external_sd/MyBooks.txt" ;
       File file = new File(fname);...etc...
    

提交回复
热议问题