Fundaments of Game Design

Slides:



Advertisements
Similar presentations
I/O Basics 12 January 2014Smitha N. Pai, CSE Dept.1.
Advertisements

Reading and Writing Text Files Svetlin Nakov Telerik Corporation
The Package Statement Group related interfaces and classes together Purpose: encapsulation and reduces name conflicts –private package classes not visible.
Streams Dwight Deugo Nesa Matic Portions of the notes for this lecture include excerpts from.
Pemrograman VisualMinggu …12… Page 1 MINGGU Ke Duabelas Pemrograman Visual Pokok Bahasan: File and Stream Tujuan Instruksional Khusus: Mahasiswa dapat.
JAVA: An Introduction to Problem Solving & Programming, 7 th Ed. By Walter Savitch ISBN © 2015 Pearson Education, Inc., Upper Saddle River,
Files & Streams. Files Introduction Files are used for long-term retention of large amounts of data, even after the program that created the data terminates.
Liang, Introduction to Java Programming, Sixth Edition, (c) 2007 Pearson Education, Inc. All rights reserved L08 (Chapter 18) Binary I/O.
File Systems Files and directories Absolute and relative names Text and binary files Sequential-access and random-access files.
Creating Sequential-Access File  Serializable attribute indicates to the compiler that objects of a class can be serialized– written to or read from a.
Lecture 30 Streams and File I/O COMP1681 / SE15 Introduction to Programming.
Sequential-access file Create, read and write an object into a sequential-access file Serialize and deserialize the object to write and read from a data.
13.1 Understanding Files The File class Objects can read and write to the file system Use the File class to hold information about files and directories.
MIS316 – BUSINESS APPLICATION DEVELOPMENT – Chapter 14 – Files and Streams 1Microsoft Visual C# 2012, Fifth Edition.
Understanding Input/Output (I/O) Classes Lesson 5.
Windows Programming Using C# Windows Services, Serialization, and Isolated Storage.
Files and Streams (part 2) 1 -Based on slides from Deitel & Associates, Inc. - Revised by T. A. Yang.
Computer and Programming File I/O File Input/Output Author: Chaiporn Jaikaeo, Jittat Fakcharoenphol Edited by Supaporn Erjongmanee Lecture 13.
Lecture Set 12 Sequential Files and Structures Part B – Reading and Writing Sequential Files.
1 Binary Files ผศ. ดร. หมัดอามีน หมันหลิน Faculty of IST, MUT
CIS 270—Application Development II Chapter 14—Files and Streams.
File I/O 11_file_processing.ppt
 2006 Pearson Education, Inc. All rights reserved Files and Streams.
File I/O Static void Main( ) {... } data. Topics I/O Streams Reading and Writing Text Files Formatting Text Files Handling Stream Errors File Pointers.
JAVA: An Introduction to Problem Solving & Programming, 5 th Ed. By Walter Savitch and Frank Carrano. ISBN © 2008 Pearson Education, Inc., Upper.
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.
Chapter Ten Structures and Sequential Access Files Programming with Microsoft Visual Basic th Edition.
Reference: Lecturer Lecturer Reham O. Al-Abdul Jabba lectures for cap211 Files and Streams- I.
Serialization What is Serialization Serialization is the process of converting an object, or a connected graph of objects, stored within computer memory,
Files and Streams. Objectives Learn about the classes that support file input/output Understand the concept of abstraction and how it related to the file.
Lecture 19 Serialization Richard Gesick. Serialization Sometimes it is easier to read or write entire objects than to read and write individual fields.
CIS 270—App Dev II Big Java Chapter 19 Files and Streams.
BIM313 – Advanced Programming File Operations 1. Contents Structure of a File Reading/Writing Texts from/to Files File and Directory Operations 2.
Object Serialization.  When the data was output to disk, certain information was lost, such as the type of each value.  If the value "3" is read from.
Object Serialization. Sequential-access Text Files Sequential-access files store records In order by the record-key field Java imposes no structure on.
©SoftMoore ConsultingSlide 1 Serialization. ©SoftMoore ConsultingSlide 2 Serialization Allows objects to be written to a stream Can be used for persistence.
CS 116 OBJECT ORIENTED PROGRAMMING II LECTURE 12 GEORGE KOUTSOGIANNAKIS Copyright: 2015 Illinois Institute of Technology/ George Koutsogiannakis 1.
Input and Output 23: Input and Output
BACS 287 File-Based Programming. BACS 287 Data Hierarchy  Database - Collection of files, relationships, integrity information, etc  Files - All records.
The Memento Pattern (Behavioral) ©SoftMoore ConsultingSlide 1.
JAVA: An Introduction to Problem Solving & Programming, 6 th Ed. By Walter Savitch ISBN © 2012 Pearson Education, Inc., Upper Saddle River,
Object-Oriented Application Development Using VB.NET 1 Chapter 13 Introduction to Data Access Classes and Persistence.
Files and Streams. Objectives Learn about the classes that support file input/output Understand the concept of abstraction and how it related to the file.
Computer Science: A Structured Programming Approach Using C1 Objectives ❏ To understand the differences between text and binary files ❏ To write programs.
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
Lecture 2 Fundamental File: Processing Operations
Lecture 18 File I/O Richard Gesick. File Input / Output Consider that a program may want to make its data persistent (or not rely upon the user for input)
OBJECT ORIENTED PROGRAMMING II LECTURE 21 GEORGE KOUTSOGIANNAKIS
Using the Console.
Input and Output 23: Input and Output
Object Writing in files
18 Files and Streams.
Memento Design Pattern
I/O Basics.
Chapter 17 Binary I/O 1.
Files and Streams Lect3 CT1411.
I/O Streams- Basics Byte Streams and Character Streams
Sequential Input and Output using Text Files
Serialization and Deserialization Bullet points from Head First Java, Ch Dec-18 serialization.ppt.
Files & Streams.
Fundamentals of Data Structures
Chapter 3.5 Input and Output
Files and Streams Lect10 GC201 12/1/2015.
CSE 331 Memento Pattern slides created by Marty Stepp based on materials by M. Ernst, S. Reges, D. Notkin, R. Mercer, Wikipedia
OBJECT ORIENTED PROGRAMMING II LECTURE 22 GEORGE KOUTSOGIANNAKIS
Lecture 16 File I/O Richard Gesick.
CIS16 Application Development and Programming using Visual Basic.net
Chapter 11 Saving Data and Objects In Files
Lecture 18 File I/O CSE /5/2019.
OO Java Programming Input Output.
Presentation transcript:

Fundaments of Game Design File IO and Serialization Richard Gesick

Objectives Reading and writing files Data path vs persistent data path Serialization of data

File Input / Output Consider that a program may want to make its data persistent (or not rely upon the user for input) Reading from and writing to a file is conceptually the same as reading/writing to the console

Streams Streams hold data Input streams provide data to the program (keyboard and ReadLine) The program places data onto output streams (console and WriteLine)

Process: Open the file stream (many "modes" - read, write, append, create, etc.) Do what you need to do (read/write) Close the file stream (freeing it for use by other programs) You can imagine that there is an "active cursor" that is moved around the file as you read/write

Opening / Closing Files Opening the file StreamReader sr = new StreamReader("data.txt"); StreamWriter sw = new StreamWriter("output.txt"); Closing the file sr.Close(); sw.Close();

Reading / Writing data Reading data from the file int x = Int32.Parse(sr.ReadLine()); or while (!sr.EndOfStream) { Console.WriteLine(sr.ReadLine()); } Writing data to the file sw.WriteLine(42);

In Unity In order to read a file from the Unity assets folder, use Application.dataPath + the file name rather than just the file name. sr= new StreamReader(“Application.dataPath”+”/”+filename); You can also use Application.persistentDataPath which stores the file in the “hidden” company name folder inside the LocalLow folder inside the App Data folder.

Serialization Sometimes it is easier to read or write entire objects than to read and write individual fields. C# provides such a mechanism, called object serialization. A serialized object is an object represented as a sequence of bytes that includes the object’s data, its type and the types of data stored in the object. After a serialized object has been written to a file, it can be read from the file and deserialized.

Serialization you probably won't be able to read it via a text editor If you are writing binary information into a file, you probably won't be able to read it via a text editor Works on objects, but the class must be marked as serializable (and is recursive)

Serialization Class BinaryFormatter enables entire objects to be written to or read from a stream. BinaryFormatter method Serialize writes an object’s representation to a file. BinaryFormatter method Deserialize reads this representation from a file and reconstructs the original object. Both methods throw a SerializationException if an error occurs during serialization or deserialization.

Creating a File Using Object Serialization The classes for objects that we wish to serialize must include this attribute in their declarations or must implement interface ISerializable. In a serializable class, you must ensure that every instance variable of the class is also serializable.

Creating a File Using Object Serialization All simple-type variables and strings are serializable. For variables of reference types, their types must be serializable. By default, array objects are serializable. However, if the array contains references to other objects, those objects may or may not be serializable.