Saving Data on Android


Utility.kt . The code for the  READ



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

Utility.kt
.
The code for the 
READ
 and 
DELETE
 button click events are similar to what you 
added for the 
WRITE
 button; these already exist in the sample project.
It’s time for the next step!
Saving Data on Android
Chapter 1: Using Files
raywenderlich.com
23


Open 
InternalFileRepository.kt
 and locate 
addNote
. Then, add the following to the 
body of the method:
context.openFileOutput(note.fileName, Context.MODE_PRIVATE).use 
{ output -> 
  output.write(note.noteText.toByteArray()) 
}
This code opens the file in 
fileOutputStream
 using the 
Context.MODE_PRIVATE
 
flag; using this flag makes this file private to this app. The 
FileOutputStream
 is a 
Closeable
 resource so we can manage it using the 
use
 Kotlin function. The note’s 
text is converted to a 
ByteArray
 and written to the file.
Run the program. Enter 
Test.txt
 for the file name and some text for the note. When 
you’re ready, tap the 
WRITE
 button. If the write is successful, the 
EditText
 controls 
will clear. Otherwise, the stacktrace is printed to Logcat.
Now that you’ve learned how to read, write and delete files on the internal storage, 
wouldn’t it be nice to see a visual representation of the files in the file system?

Download 19,28 Mb.

Do'stlaringiz bilan baham:
1   ...   18   19   20   21   22   23   24   25   ...   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