read and write files by the end of this lab you will be able to: write a file in internal storage ...

8
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 CS440 1

Upload: spencer-griffin

Post on 17-Jan-2016

215 views

Category:

Documents


0 download

TRANSCRIPT

Page 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

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

Page 2: 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

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

Page 3: 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

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.

Page 4: 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

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.

Page 5: 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

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

Page 6: 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

CS440

6

How do you know you have created the file?

How do you know you have written in the file?

The endless doubt

Page 7: 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

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?