View
41
Download
6
Category
Preview:
DESCRIPTION
Read and Write Files. By the end of this lab you will be able to: Write a file in internal storage Read a file from internal storage Write a file on SD card Read a file from SD card Install an app on the Android emulator. Prerequisites. Main classes you will need to learn about: - PowerPoint PPT Presentation
Citation preview
CS440
1
Read and Write Files
By the end of this lab you will be able to: Write a file in internal storage Read a file from internal storage Write a file on SD card Read a file from SD card Install an app on the Android emulator
2
Prerequisites
Main classes you will need to learn about: BufferedReader BufferedWriter OutputStreamReader OutputStreamWriter StringBuffer
Main methods you will need to learn: readLine!! Write openFileOutput openFileInput
3
Java.io
Class Description BufferedInputStream Used for creating an internal buffer
array. It supports the mark and reset methods.
BufferedOutputStream Used for byte write to output stream. It implements a buffered output stream.
BufferedReader Used to read text from character input stream and buffering characters. It also reads characters, arrays and lines.
BufferedWriter Used to write text from character output stream and buffering characters. It also writes characters, arrays and lines.
4
Java.io
Class DescriptionFile Shows a file and directory
pathnames.FileReader Used for reading characters in file.FileWriter Used for writing characters in file.InputStream Represents an input stream of
bytes.InputStreamReader Used to read bytes and decode
them into characters.OutputStream Represents an output stream of
bytes. OutputStreamWriter Used to write bytes and decode
them into characters.
CS440
5
Create a file in internal storage Create all the necessary objects to write in
this file BufferedWriter OutputStreamWriter
Write in the file Read from file
Create all the necessary objects to read from this file BufferedReader OutputStreamReader
The mission
CS440
6
How do you know you have created the file?
How do you know you have written in the file?
The endless doubt
CS440
7
Create a file in the SD card Create all the necessary objects to write in
this file BufferedWriter OutputStreamWriter
Write in the file Read from file
Create all the necessary objects to read from this file BufferedReader OutputStreamReader
The mission impossible?
CS440
8
References
http://www.vogella.de/articles/AndroidFileSystem/article.html
http://www.tylerfrankenstein.com/create-android-emulator-sd-card-and-write-data-to-it
http://stackoverflow.com/questions/9351904/cannot-write-to-sdcard-in-android-emulator
Recommended