際際滷

際際滷Share a Scribd company logo
Data Management, Internal Memory
Step1. Create a newAndroidProject.
Step2. Add the followingcode toyouractivityxml file.
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/scrollView1"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<LinearLayout
android:id="@+id/linearLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
</LinearLayout>
</ScrollView>
Step3. Add the followingcode intoyourvalues.xml file
Step4. Addfollowingcode onthe oncreate methodof youractivity
LinearLayout ll = (LinearLayout) findViewById(R.id.linearLayout);
// Check whether fileName already exists in directory used
// by the openFileOutput() method.
// If the text file doesn't exist, then create it now
if (!getFileStreamPath(fileName).exists()) {
try {
writeFile();
} catch (FileNotFoundException e) {
Log.i(TAG, "FileNotFound");
}
}
// Read the data from the text file and display it
try {
readFile(ll);
} catch (IOException e) {
Log.i(TAG, "IOException");
}
Step5. Add the writeFilefunctioninyourmainactivity
private void writeFile() throws FileNotFoundException {
FileOutputStream fos = openFileOutput(fileName, MODE_PRIVATE);
PrintWriter pw = new PrintWriter(new BufferedWriter(
new OutputStreamWriter(fos)));
pw.println("Line 1: This is a test of the File Writing API");
pw.println("Line 2: This is a test of the File Writing API");
pw.println("Line 3: This is a test of the File Writing API");
pw.close();
}
Step6. Add The readFile functioninyourmainactivity
private void readFile(LinearLayout ll) throws IOException {
FileInputStream fis = openFileInput(fileName);
BufferedReader br = new BufferedReader(new InputStreamReader(fis));
String line = "";
while (null != (line = br.readLine())) {
TextView tv = new TextView(this);
tv.setTextSize(24);
tv.setText(line);
ll.addView(tv);
}
br.close();
}
Step7. Done.
Ad

Recommended

20200815 inversions
20200815 inversions
Chiwon Song
MA DHARSH.pptx
MA DHARSH.pptx
DharshiniB15
Android datastorage
Android datastorage
Krazy Koder
Internal Storage in Mobile Application Development.pptx
Internal Storage in Mobile Application Development.pptx
Gowthami476224
Data Storage In Android
Data Storage In Android
Aakash Ugale
Android Data Storagefinal
Android Data Storagefinal
Nakka Srilakshmi
Android App Development - 09 Storage
Android App Development - 09 Storage
Diego Grancini
Android - Saving data
Android - Saving data
Matteo Bonifazi
03 programmation mobile - android - (stockage, multithreads, web services)
03 programmation mobile - android - (stockage, multithreads, web services)
TECOS
Memory management
Memory management
Vikash Patel
6CS027 Lecture 5 Files and Database Storage (1).pptx
6CS027 Lecture 5 Files and Database Storage (1).pptx
kusumjeewanthi
Lab4 - android
Lab4 - android
Lilia Sfaxi
Android-data storage in android-chapter21
Android-data storage in android-chapter21
Dr. Ramkumar Lakshminarayanan
Data management
Data management
Madrasah Idrisiah
Data management
Data management
maamir farooq
Storage 8
Storage 8
Michael Shrove
Assets, files, and data parsing
Assets, files, and data parsing
Aly Arman
Android Training (Storing & Shared Preferences)
Android Training (Storing & Shared Preferences)
Khaled Anaqwa
Android Data Persistence
Android Data Persistence
Jussi Pohjolainen
Android | Busy Java Developers Guide to Android: Persistence | Ted Neward
Android | Busy Java Developers Guide to Android: Persistence | Ted Neward
JAX London
Android App Development 05 : Saving Data
Android App Development 05 : Saving Data
Anuchit Chalothorn
Everything about storage - DroidconMtl 2015
Everything about storage - DroidconMtl 2015
Cindy Potvin
Lecture 8: Android Types of Storage.pptx
Lecture 8: Android Types of Storage.pptx
Yousef Alamir
Dicoding Developer Coaching #19: Android | Menyimpan Database Secara Local di...
Dicoding Developer Coaching #19: Android | Menyimpan Database Secara Local di...
DicodingEvent
Mobile Application Development -Lecture 11 & 12.pdf
Mobile Application Development -Lecture 11 & 12.pdf
AbdullahMunir32
Android Lab Test : Reading the foot file list (english)
Android Lab Test : Reading the foot file list (english)
Bruno Delb
Ooad lab1
Ooad lab1
maamir farooq
Lesson 03
Lesson 03
maamir farooq
Lesson 02
Lesson 02
maamir farooq
Php client libray
Php client libray
maamir farooq

More Related Content

Similar to 2. file internal memory (18)

03 programmation mobile - android - (stockage, multithreads, web services)
03 programmation mobile - android - (stockage, multithreads, web services)
TECOS
Memory management
Memory management
Vikash Patel
6CS027 Lecture 5 Files and Database Storage (1).pptx
6CS027 Lecture 5 Files and Database Storage (1).pptx
kusumjeewanthi
Lab4 - android
Lab4 - android
Lilia Sfaxi
Android-data storage in android-chapter21
Android-data storage in android-chapter21
Dr. Ramkumar Lakshminarayanan
Data management
Data management
Madrasah Idrisiah
Data management
Data management
maamir farooq
Storage 8
Storage 8
Michael Shrove
Assets, files, and data parsing
Assets, files, and data parsing
Aly Arman
Android Training (Storing & Shared Preferences)
Android Training (Storing & Shared Preferences)
Khaled Anaqwa
Android Data Persistence
Android Data Persistence
Jussi Pohjolainen
Android | Busy Java Developers Guide to Android: Persistence | Ted Neward
Android | Busy Java Developers Guide to Android: Persistence | Ted Neward
JAX London
Android App Development 05 : Saving Data
Android App Development 05 : Saving Data
Anuchit Chalothorn
Everything about storage - DroidconMtl 2015
Everything about storage - DroidconMtl 2015
Cindy Potvin
Lecture 8: Android Types of Storage.pptx
Lecture 8: Android Types of Storage.pptx
Yousef Alamir
Dicoding Developer Coaching #19: Android | Menyimpan Database Secara Local di...
Dicoding Developer Coaching #19: Android | Menyimpan Database Secara Local di...
DicodingEvent
Mobile Application Development -Lecture 11 & 12.pdf
Mobile Application Development -Lecture 11 & 12.pdf
AbdullahMunir32
Android Lab Test : Reading the foot file list (english)
Android Lab Test : Reading the foot file list (english)
Bruno Delb
03 programmation mobile - android - (stockage, multithreads, web services)
03 programmation mobile - android - (stockage, multithreads, web services)
TECOS
Memory management
Memory management
Vikash Patel
6CS027 Lecture 5 Files and Database Storage (1).pptx
6CS027 Lecture 5 Files and Database Storage (1).pptx
kusumjeewanthi
Lab4 - android
Lab4 - android
Lilia Sfaxi
Assets, files, and data parsing
Assets, files, and data parsing
Aly Arman
Android Training (Storing & Shared Preferences)
Android Training (Storing & Shared Preferences)
Khaled Anaqwa
Android | Busy Java Developers Guide to Android: Persistence | Ted Neward
Android | Busy Java Developers Guide to Android: Persistence | Ted Neward
JAX London
Android App Development 05 : Saving Data
Android App Development 05 : Saving Data
Anuchit Chalothorn
Everything about storage - DroidconMtl 2015
Everything about storage - DroidconMtl 2015
Cindy Potvin
Lecture 8: Android Types of Storage.pptx
Lecture 8: Android Types of Storage.pptx
Yousef Alamir
Dicoding Developer Coaching #19: Android | Menyimpan Database Secara Local di...
Dicoding Developer Coaching #19: Android | Menyimpan Database Secara Local di...
DicodingEvent
Mobile Application Development -Lecture 11 & 12.pdf
Mobile Application Development -Lecture 11 & 12.pdf
AbdullahMunir32
Android Lab Test : Reading the foot file list (english)
Android Lab Test : Reading the foot file list (english)
Bruno Delb

More from maamir farooq (20)

Ooad lab1
Ooad lab1
maamir farooq
Lesson 03
Lesson 03
maamir farooq
Lesson 02
Lesson 02
maamir farooq
Php client libray
Php client libray
maamir farooq
Swiftmailer
Swiftmailer
maamir farooq
Lect15
Lect15
maamir farooq
Lec 7
Lec 7
maamir farooq
Lec 6
Lec 6
maamir farooq
Lec 5
Lec 5
maamir farooq
J query 1.7 cheat sheet
J query 1.7 cheat sheet
maamir farooq
Assignment
Assignment
maamir farooq
Java script summary
Java script summary
maamir farooq
Lec 3
Lec 3
maamir farooq
Lec 2
Lec 2
maamir farooq
Lec 1
Lec 1
maamir farooq
Css summary
Css summary
maamir farooq
Manual of image processing lab
Manual of image processing lab
maamir farooq
Session management
Session management
maamir farooq
Content provider
Content provider
maamir farooq
Android sq lite database tutorial
Android sq lite database tutorial
maamir farooq
Ad

Recently uploaded (20)

2025 June Year 9 Presentation: Subject selection.pptx
2025 June Year 9 Presentation: Subject selection.pptx
mansk2
Learning Styles Inventory for Senior High School Students
Learning Styles Inventory for Senior High School Students
Thelma Villaflores
Romanticism in Love and Sacrifice An Analysis of Oscar Wildes The Nightingal...
Romanticism in Love and Sacrifice An Analysis of Oscar Wildes The Nightingal...
KaryanaTantri21
LDMMIA Yoga S10 Free Workshop Grad Level
LDMMIA Yoga S10 Free Workshop Grad Level
LDM & Mia eStudios
How to Add New Item in CogMenu in Odoo 18
How to Add New Item in CogMenu in Odoo 18
Celine George
LAZY SUNDAY QUIZ "A GENERAL QUIZ" JUNE 2025 SMC QUIZ CLUB, SILCHAR MEDICAL CO...
LAZY SUNDAY QUIZ "A GENERAL QUIZ" JUNE 2025 SMC QUIZ CLUB, SILCHAR MEDICAL CO...
Ultimatewinner0342
A Visual Introduction to the Prophet Jeremiah
A Visual Introduction to the Prophet Jeremiah
Steve Thomason
HistoPathology Ppt. Arshita Gupta for Diploma
HistoPathology Ppt. Arshita Gupta for Diploma
arshitagupta674
NSUMD_M1 Library Orientation_June 11, 2025.pptx
NSUMD_M1 Library Orientation_June 11, 2025.pptx
Julie Sarpy
Public Health For The 21st Century 1st Edition Judy Orme Jane Powell
Public Health For The 21st Century 1st Edition Judy Orme Jane Powell
trjnesjnqg7801
June 2025 Progress Update With Board Call_In process.pptx
June 2025 Progress Update With Board Call_In process.pptx
International Society of Service Innovation Professionals
Great Governors' Send-Off Quiz 2025 Prelims IIT KGP
Great Governors' Send-Off Quiz 2025 Prelims IIT KGP
IIT Kharagpur Quiz Club
M&A5 Q1 1 differentiate evolving early Philippine conventional and contempora...
M&A5 Q1 1 differentiate evolving early Philippine conventional and contempora...
ErlizaRosete
CRYPTO TRADING COURSE BY FINANCEWORLD.IO
CRYPTO TRADING COURSE BY FINANCEWORLD.IO
AndrewBorisenko3
K12 Tableau User Group virtual event June 18, 2025
K12 Tableau User Group virtual event June 18, 2025
dogden2
How to Customize Quotation Layouts in Odoo 18
How to Customize Quotation Layouts in Odoo 18
Celine George
GREAT QUIZ EXCHANGE 2025 - GENERAL QUIZ.pptx
GREAT QUIZ EXCHANGE 2025 - GENERAL QUIZ.pptx
Ronisha Das
ENGLISH-5 Q1 Lesson 1.pptx - Story Elements
ENGLISH-5 Q1 Lesson 1.pptx - Story Elements
Mayvel Nadal
Filipino 9 Maikling Kwento Ang Ama Panitikang Asiyano
Filipino 9 Maikling Kwento Ang Ama Panitikang Asiyano
sumadsadjelly121997
This is why students from these 44 institutions have not received National Se...
This is why students from these 44 institutions have not received National Se...
Kweku Zurek
2025 June Year 9 Presentation: Subject selection.pptx
2025 June Year 9 Presentation: Subject selection.pptx
mansk2
Learning Styles Inventory for Senior High School Students
Learning Styles Inventory for Senior High School Students
Thelma Villaflores
Romanticism in Love and Sacrifice An Analysis of Oscar Wildes The Nightingal...
Romanticism in Love and Sacrifice An Analysis of Oscar Wildes The Nightingal...
KaryanaTantri21
LDMMIA Yoga S10 Free Workshop Grad Level
LDMMIA Yoga S10 Free Workshop Grad Level
LDM & Mia eStudios
How to Add New Item in CogMenu in Odoo 18
How to Add New Item in CogMenu in Odoo 18
Celine George
LAZY SUNDAY QUIZ "A GENERAL QUIZ" JUNE 2025 SMC QUIZ CLUB, SILCHAR MEDICAL CO...
LAZY SUNDAY QUIZ "A GENERAL QUIZ" JUNE 2025 SMC QUIZ CLUB, SILCHAR MEDICAL CO...
Ultimatewinner0342
A Visual Introduction to the Prophet Jeremiah
A Visual Introduction to the Prophet Jeremiah
Steve Thomason
HistoPathology Ppt. Arshita Gupta for Diploma
HistoPathology Ppt. Arshita Gupta for Diploma
arshitagupta674
NSUMD_M1 Library Orientation_June 11, 2025.pptx
NSUMD_M1 Library Orientation_June 11, 2025.pptx
Julie Sarpy
Public Health For The 21st Century 1st Edition Judy Orme Jane Powell
Public Health For The 21st Century 1st Edition Judy Orme Jane Powell
trjnesjnqg7801
Great Governors' Send-Off Quiz 2025 Prelims IIT KGP
Great Governors' Send-Off Quiz 2025 Prelims IIT KGP
IIT Kharagpur Quiz Club
M&A5 Q1 1 differentiate evolving early Philippine conventional and contempora...
M&A5 Q1 1 differentiate evolving early Philippine conventional and contempora...
ErlizaRosete
CRYPTO TRADING COURSE BY FINANCEWORLD.IO
CRYPTO TRADING COURSE BY FINANCEWORLD.IO
AndrewBorisenko3
K12 Tableau User Group virtual event June 18, 2025
K12 Tableau User Group virtual event June 18, 2025
dogden2
How to Customize Quotation Layouts in Odoo 18
How to Customize Quotation Layouts in Odoo 18
Celine George
GREAT QUIZ EXCHANGE 2025 - GENERAL QUIZ.pptx
GREAT QUIZ EXCHANGE 2025 - GENERAL QUIZ.pptx
Ronisha Das
ENGLISH-5 Q1 Lesson 1.pptx - Story Elements
ENGLISH-5 Q1 Lesson 1.pptx - Story Elements
Mayvel Nadal
Filipino 9 Maikling Kwento Ang Ama Panitikang Asiyano
Filipino 9 Maikling Kwento Ang Ama Panitikang Asiyano
sumadsadjelly121997
This is why students from these 44 institutions have not received National Se...
This is why students from these 44 institutions have not received National Se...
Kweku Zurek
Ad

2. file internal memory

  • 1. Data Management, Internal Memory Step1. Create a newAndroidProject. Step2. Add the followingcode toyouractivityxml file. <?xml version="1.0" encoding="utf-8"?> <ScrollView xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/scrollView1" android:layout_width="match_parent" android:layout_height="match_parent" > <LinearLayout android:id="@+id/linearLayout" android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="vertical" > </LinearLayout> </ScrollView> Step3. Add the followingcode intoyourvalues.xml file Step4. Addfollowingcode onthe oncreate methodof youractivity LinearLayout ll = (LinearLayout) findViewById(R.id.linearLayout); // Check whether fileName already exists in directory used // by the openFileOutput() method. // If the text file doesn't exist, then create it now if (!getFileStreamPath(fileName).exists()) { try { writeFile(); } catch (FileNotFoundException e) { Log.i(TAG, "FileNotFound"); } } // Read the data from the text file and display it try { readFile(ll); } catch (IOException e) {
  • 2. Log.i(TAG, "IOException"); } Step5. Add the writeFilefunctioninyourmainactivity private void writeFile() throws FileNotFoundException { FileOutputStream fos = openFileOutput(fileName, MODE_PRIVATE); PrintWriter pw = new PrintWriter(new BufferedWriter( new OutputStreamWriter(fos))); pw.println("Line 1: This is a test of the File Writing API"); pw.println("Line 2: This is a test of the File Writing API"); pw.println("Line 3: This is a test of the File Writing API"); pw.close(); } Step6. Add The readFile functioninyourmainactivity private void readFile(LinearLayout ll) throws IOException { FileInputStream fis = openFileInput(fileName); BufferedReader br = new BufferedReader(new InputStreamReader(fis)); String line = ""; while (null != (line = br.readLine())) { TextView tv = new TextView(this); tv.setTextSize(24); tv.setText(line); ll.addView(tv); } br.close(); } Step7. Done.