Saving Data on Android


Reading from internal storage



Download 19,28 Mb.
Pdf ko'rish
bet26/292
Sana24.01.2022
Hajmi19,28 Mb.
#407089
1   ...   22   23   24   25   26   27   28   29   ...   292
Bog'liq
Bailey J., Dominguez A., Djermanovic D. - Saving Data on Android (1st Edition) - 2019

Reading from internal storage
Replace the current 
return
 statement in the 
getNote
 in 
InternalFileRepository
 
with the current code:
// 1
 
val
 note = Note(fileName, 
""

// 2
 
context.openFileInput(fileName).use { stream -> 
  
// 3
 
  
val
 text = stream.bufferedReader().use { 
    it.readText() 
  } 
  
// 4
 
  note.noteText = text 

// 5
 
return
 note
Here’s how it works:
1. Declare a 
Note
, passing in a 
fileName
 and an empty string so that a valid object 
gets returned from this function even if the read operation fails.
2. Open and consume the 
FileInputStream
 with 
use
.
3. Open a 
BufferedReader
 with 
use
 so that you can efficiently read the file.
4. Assign the text that was read to the file to 
note.noteText
.
5. Return 
note
.
Run the app and enter the name of a file you previously saved and then tap 
READ

The note’s text displays in the app. And that’s it! Your app can now write and read 
notes.
Up next, you’ll write the code to delete a file.

Download 19,28 Mb.

Do'stlaringiz bilan baham:
1   ...   22   23   24   25   26   27   28   29   ...   292




Ma'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©hozir.org 2024
ma'muriyatiga murojaat qiling

kiriting | ro'yxatdan o'tish
    Bosh sahifa
юртда тантана
Боғда битган
Бугун юртда
Эшитганлар жилманглар
Эшитмадим деманглар
битган бодомлар
Yangiariq tumani
qitish marakazi
Raqamli texnologiyalar
ilishida muhokamadan
tasdiqqa tavsiya
tavsiya etilgan
iqtisodiyot kafedrasi
steiermarkischen landesregierung
asarlaringizni yuboring
o'zingizning asarlaringizni
Iltimos faqat
faqat o'zingizning
steierm rkischen
landesregierung fachabteilung
rkischen landesregierung
hamshira loyihasi
loyihasi mavsum
faolyatining oqibatlari
asosiy adabiyotlar
fakulteti ahborot
ahborot havfsizligi
havfsizligi kafedrasi
fanidan bo’yicha
fakulteti iqtisodiyot
boshqaruv fakulteti
chiqarishda boshqaruv
ishlab chiqarishda
iqtisodiyot fakultet
multiservis tarmoqlari
fanidan asosiy
Uzbek fanidan
mavzulari potok
asosidagi multiservis
'aliyyil a'ziym
billahil 'aliyyil
illaa billahil
quvvata illaa
falah' deganida
Kompyuter savodxonligi
bo’yicha mustaqil
'alal falah'
Hayya 'alal
'alas soloh
Hayya 'alas
mavsum boyicha


yuklab olish