Android Development: File System Approaches Richard S. Stansbury 2015.

Slides:



Advertisements
Similar presentations
1 Streams and Input/Output Files Part 3. 2 Handling Primitive Data Types The basic input and output streams provide read/write methods that can be used.
Advertisements

Lecture 15: I/O and Parsing
The Package Statement Group related interfaces and classes together Purpose: encapsulation and reduces name conflicts –private package classes not visible.
Java File I/O. File I/O is important! Being able to write and read from files is necessary and is also one common practice of a programmer. Examples include.
MOD III. Input / Output Streams Byte streams Programs use byte streams to perform input and output of 8-bit bytes. This Stream handles the 8-bit.
Text File I/O. Text Files and Binary Files Files that are designed to be read by human beings, and that can be read or written with an editor are called.
Geoff Holmes Overview IO Zoo Stream I/O File I/O Buffering Random-Access Text Streams Examples Serialization Java IO – programs that start with import.
Files Files are used to store long term data. –Typically referred to as persistent data. –A file is a group of related records. –A list of friends addresses.
©The McGraw-Hill Companies, Inc. Permission required for reproduction or display. 4 th Ed Chapter N - 1 Chapter 12 File Input and Output.
Unit 201 FILE IO Types of files Opening a text file for reading Reading from a text file Opening a text file for writing/appending Writing/appending to.
Files and Streams CS 21a. 10/02/05 L18: Files Slide 2 Copyright 2005, by the authors of these slides, and Ateneo de Manila University. All rights reserved.
©The McGraw-Hill Companies, Inc. Permission required for reproduction or display. 4 th Ed Chapter N - 1 Chapter 12 File Input and Output.
CS102--Object Oriented Programming Lecture 14: – File I/O BufferedReader The File class Write to /read from Binary files Copyright © 2008 Xiaoyan Li.
Java I/O – what does it include? Command line user interface –Initial arguments to main program –System.in and System.out GUI Hardware –Disk drives ->
Java Review 2. The Agenda The following topics were highlighted to me as issues: –File IO (Rem) –Wrappers (Rem) –Interfaces (Rem) –Asymptotic Notation.
CIS 068 JAVA I/O: Streams and Files. CIS 068 I/O Usual Purpose: storing data to ‘nonvolatile‘ devices, e.g. harddisk Classes provided by package java.io.
Networking Nasrullah. Input stream Most clients will use input streams that read data from the file system (FileInputStream), the network (getInputStream()/getInputStream()),
CSE 486/586, Spring 2013 CSE 486/586 Distributed Systems Content Providers & Services.
Files and Streams 1 -Based on slides from Deitel & Associates, Inc. - Revised by T. A. Yang.
Files and Streams. Java I/O File I/O I/O streams provide data input/output solutions to the programs. A stream can represent many different kinds of sources.
CS378 - Mobile Computing Persistence. Saving State We have already seen saving app state into a Bundle on orientation changes or when an app is killed.
5-Oct-15 Air Force Institute of Technology Electrical and Computer Engineering Object-Oriented Programming Design Topic : Streams and Files Maj Joel Young.
Data Storage: Part 2 (File System). Internal Storage versus External Storage Internal storage − for private data –By default, files saved to the internal.
Prepared by : A.Alzubair Hassan Kassala university Dept. Computer Science Lecture 2 I/O Streams 1.
CSE 486/586, Spring 2012 CSE 486/586 Distributed Systems Recitation.
Console Input. So far… All the inputs for our programs have been hard-coded in the main method or inputted using the dialog boxes of BlueJ It’s time to.
Files. What are files? A series of data bits. a place for output a place to obtain input.
Streams Reading: 2 nd Ed: , rd Ed: 11.1, 19.1, 19.4
File I/O Static void Main( ) {... } data. Topics I/O Streams Reading and Writing Text Files Formatting Text Files Handling Stream Errors File Pointers.
Chapter 9 1 Chapter 9 – Part 1 l Overview of Streams and File I/O l Text File I/O l Binary File I/O l File Objects and File Names Streams and File I/O.
Program data (instance variables, local variables, and parameters) is transient, because its lifetime ends with the program...if not, before. Sometimes.
Based on OOP with Java, by David J. Barnes Input-Output1 The java.io Package 4 Text files Reader and Writer classes 4 Byte stream files InputStream, FileInputStream,
OOP with Java, David J. Barnes Input-Output1 A complex issue in programming language design. The interface to the outside world. –Differences must be accommodated.
JAVA I/O © EnhanceEdu, IIIT Hyderabad. Contents 3/29/2010EnhanceEdu, IIIT - H 2  Command Line I/O  File Class  Streams  Byte Streams [Low level and.
Android Storage. There are several options for storage of data with Android We can put data into a preferences file. We can put data into a ‘normal’ file.
Nilesh Singh Local Data Storage option Android provides several options for you to save persistent application data. - Shared preferences - Creation.
1 Recitation 8. 2 Outline Goals of this recitation: 1.Learn about loading files 2.Learn about command line arguments 3.Review of Exceptions.
By Rachel Thompson and Michael Deck.  Java.io- a package for input and output  File I/O  Reads data into and out of the console  Writes and reads.
CS378 - Mobile Computing Persistence. Saving State We have already seen saving app state into a Bundle on orientation changes or when an app is killed.
CS101 Lab “File input/Output”. File input, output File : binary file, text file READ/WRITE class of “text file” - File Reading class : FileReader, BufferedReader.
Persistence Dr. David Janzen Except as otherwise noted, the content of this presentation is licensed under the Creative Commons Attribution 2.5 License.
5-Dec-15 Sequential Files and Streams. 2 File Handling. File Concept.
Files and Streams CS /02/05 L7: Files Slide 2 Copyright 2005, by the authors of these slides, and Ateneo de Manila University. All rights reserved.
CS 116 OBJECT ORIENTED PROGRAMMING II LECTURE 11 GEORGE KOUTSOGIANNAKIS Copyright: 2015 / Illinois Institute of Technology/George Koutsogiannakis 1.
Java Enterprise Edition Programming Page 1 of 9Configuring Servlets Web Application Context Name  In multiple web applications, a “context name” is used.
CSI 3125, Preliminaries, page 1 Java I/O. CSI 3125, Preliminaries, page 2 Java I/O Java I/O (Input and Output) is used to process the input and produce.
PROG Mobile Java Application Development PROG Mobile Java Application Development Data Storage, Continued.
I/O Basics 26 January Aside from print( ) and println( ), none of the I/O methods have been used significantly. The reason is simple: most real.
Chapter - 11 Introduction to File and Streams This chapter includes -  Defining a File  Testing and Checking File Objects  Accessing File Objects.
I/O Basics Java does provide strong, flexible support for I/O related to files and networks. Java’s console based interaction is limited since in real.
Files and Serialization. Files Used to transfer data to and from secondary storage.
CSI 3125, Preliminaries, page 1 Files. CSI 3125, Preliminaries, page 2 Reading and Writing Files Java provides a number of classes and methods that allow.
1 CSE 331 Memento Pattern and Serialization slides created by Marty Stepp based on materials by M. Ernst, S. Reges, D. Notkin, R. Mercer, Wikipedia
1 Input-Output A complex issue in programming language design. The interface to the outside world. –Differences must be accommodated as transparently as.
Data Persistence Chapter 9. Objectives Learn about data storage methods Understand use of Shared Preferences Understand file-based storage and the differences.
Sequential files creation & writing
COMP Streams and File I/O
Data Storage: Part 2 (File System)
CS371m - Mobile Computing Persistence.
Android Application Data Storage 1.
Lesson 8: More File I/O February 5, 2008
Introduction to programming in java
University of Central Florida COP 3330 Object Oriented Programming
I/O Basics.
Mobile Computing With Android ACST 4550 Android Data Storage
OBJECT ORIENTED PROGRAMMING II LECTURE 20 GEORGE KOUTSOGIANNAKIS
Streams and Readers The stream hierarchy is for reading bytes, the reader/writer hierarchy is for reading characters Unicode characters can be used internationally,
EEC 484/584 Computer Networks
David Davenport Spring 2005
Presentation transcript:

Android Development: File System Approaches Richard S. Stansbury 2015

File System-based Data Storage Packaged Files – Raw Resources – XML Resources – Assets Internal and External Storage – Options Application Specific Internal Application Specific External Public Shared Storage – Permission required for external write and/or read

Packaged Files: Raw Resources What are raw resources? – Data files of arbitrary format How are they included? – Stored in the res/raw folder – Example res/raw/blah.txt – Resources r = getResources(); – InputStream i = r.openRawResource(R.raw.blah); What can be done to/with them? – Read only – Support’s reference of static application data

Packaged Files: XML Resources Why? – If your static application data is XML, then better to include here than under raw. How? – Data stored in “res/xml/” – e.g. res/xml/blah.xml Resources r = getResources(); XMLResourceParser xml = r.getXml(R.xml.blah); What do I do with this? – Return’s an XML Pull Parser – mlPullParser.html mlPullParser.html

Packaged Files: Assets How? – Create a folder in your root folder called “assets/” – AssetManager am = getAssets(); – InputStream is = am.open( ); e.g. “content/blah.html” would access the path and folder specified in the “assets/” folder Or, – For WebView w.loadURL(file://android_asset/ );file://android_asset/ Loads the content as HTML into the webview

Example: Assets public void loadDatabase() throws IOException { AssetManager am = getAssets(); InputStream inputStream = am.open("movies.csv"); BufferedReader input = new BufferedReader(new InputStreamReader(inputStream)); String movieStr; while ((movieStr = input.readLine()) != null) { _mdb.addMovie(Movie.parseMovie(movieStr)); }

File-system Storage Access files for read/write at runtime – Persistent data Data that will remain for the life of your application (or longer) – Cached data Data that is eligible for purge periodically by other applications / system. You can open instances java.io classes such as File, InputStream, OutputWriter, etc. – Some issues must be considered on how to specify the path Internal vs. External options

File-System Storage: Internal Onboard and always available Typically the built-in flash – Note: some devices have internal flash for both the “internal storage” and “external storage” e.g. Nexus 7 Data only available to the application – Not accessible by other applications or external means (Note: exceptions for rooted devices)

File-System Storage: Internal No Path: Pass file names to: – FileInputStream fis = openFileInput( ) – FileOutputStream fos = openFileOutput(, int mode) Mode options – ntext.html#openFileOutput(java.lang.String, int) For paths: – Create file reference to root folder – Create file reference for sub-folder and filename

File-System Storage: Internal Within context – File root = getActivity().getFilesDir(); Or getActivity().getCacheDir(); – File file = new File(root, ); Now, you can create input stream or output writer (or the like) using the file File object.

File-System Storage: External Application specific storage folder – Accessible by all – File root = getActivity().getExternalFilesDir(); Application specific cache folder – Accessible by all, but eligible for random sweep – File root = getActivity().getExternalCacheDir();

File-System Storage: External External storage in root folder – File root = Environment.getExternalStorageDirectory();

File-System Storage: External Public directory (for things to share) – File root = Environment.getExternalPublicDirectory( ) : Environment. – DIRECTORY_MUSIC – DIRECTORY_PODCASTS – DIRECTORY_RINGTONES – DIRECTORY_ALARMS – DIRECTORY_NOTIFICATIONS – DIRECTORY_PICTURES – DIRECTORY_MOVIES – DIRECTORY_DOWNLOADS – DIRECTORY_DCIM

File-System Storage: Permissions Manifest.xml – If you do have write permissions, you do not need to include read permissions (but not vice-versa)

File-System Storage: Multiple Users 4.2 and later now allows multiple users – getFilesDir() and getFilesExternalDir() provides separate folders for each user

References Textbook Resources: – ent/res/Resources.html XML Pull Parser: – v1/XmlPullParser.html v1/XmlPullParser.html Asset Manager – ent/res/AssetManager.html ent/res/AssetManager.html