Computer Programming Methodology File Input

Slides:



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

Procedural Programming in C# Chapters Objectives You will be able to: Describe the most important data types available in C#. Read numeric values.
Chapter 10 Ch 1 – Introduction to Computers and Java Streams and File IO 1.
L2:CSC © Dr. Basheer M. Nasef Lecture #2 By Dr. Basheer M. Nasef.
Using Processing Stream. Predefined Streams System.in InputStream used to read bytes from the keyboard System.out PrintStream used to write bytes to the.
Shlomo Hershkop1 Introduction to java Class 1 Fall 2003 Shlomo Hershkop.
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.
03 Data types1June Data types CE : Fundamental Programming Techniques.
1 Text File I/O Overview l I/O streams l Opening a text file for reading l Reading a text file l Closing a stream l Reading numbers from a text file l.
Chapter 91 Streams and File I/O Chapter 9. 2 Reminders Project 6 released: due Nov 10:30 pm Project 4 regrades due by midnight tonight Discussion.
1 Streams Overview l I/O streams l Opening a text file for reading l Reading a text file l Closing a stream l Reading numbers from a text file l Writing.
CS102--Object Oriented Programming Lecture 14: – File I/O BufferedReader The File class Write to /read from Binary files Copyright © 2008 Xiaoyan Li.
Strings and File I/O. Strings Java String objects are immutable Common methods include: –boolean equalsIgnoreCase(String str) –String toLowerCase() –String.
The switch statement: an N-way selection statement.
Week 2 - Friday.  What did we talk about last time?  Data representation  Binary numbers  Types  int  boolean  double  char  String.
Intro to Java Programming  A computer follows the instruction precisely and exactly.  Anything has to be declared and defined before it can be used.
Liang, Introduction to Java Programming, Tenth Edition, (c) 2015 Pearson Education, Inc. All rights reserved. 1 Chapter 2 Elementary Programming.
Two Ways to Store Data in a File Text format Binary format.
CSI 1390: Introduction to Computers TA: Tapu Kumar Ghose Office: STE 5014
1 Java Console I/O Introduction. 2 Java I/O You may have noticed that all the I/O that we have done has been output The reasons –Java I/O is based on.
Java means Coffee Java Coffee Beans The name “JAVA” was taken from a cup of coffee.
Chapter 2: Java Fundamentals
1 Week 12 l Overview of Streams and File I/O l Text File I/O Streams and File I/O.
JAVA PROGRAMMING BASICS CHAPTER 2. History of Java Begin with project Green in 1991 founded by Patrick Noughton, Mike Sheridan and James Gosling who worked.
Introduction to Programming G50PRO University of Nottingham Unit 11 : Files Input/Ouput Paul Tennent
Mixing integer and floating point numbers in an arithmetic operation.
Introduction to Java Primitive Types Operators Basic input and output.
Using the while-statement to process data files. General procedure to access a data file General procedure in computer programming to read data from a.
A Simple Java Program //This program prints Welcome to Java! public class Welcome { public static void main(String[] args) { public static void main(String[]
Chapter 2 Input, Variables and Data Types. JAVA Input JAVA input is not straightforward and is different depending on the JAVA environment that you are.
School of Computer Science & Information Technology G6DICP - Lecture 4 Variables, data types & decision making.
BHCSI Programming Contests. Three contests Mock Contest #1  Friday, July 16 th  2:15 – 4:45pm UCF High School Online Contest  Thursday, July 22 nd.
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.
Java – Variables and Constants By: Dan Lunney. Declaring Variables All variables must be declared before they can be used A declaration takes the form:
CSCI 1100/1202 January 23, Class Methods Some methods can be invoked through the class name, instead of through an object of the class These methods.
Strings and File I/O. Strings Java String objects are immutable Common methods include: –boolean equalsIgnoreCase(String str) –String toLowerCase() –String.
JAVA Practical Unary operators 2. Using Reals 3. Conversions 4. Type Casting 5. Scope 6. Constants.
Topics for today: 1.Comments 2.Data types 3.Variable declaration.
Java IO Exploring the java.io package and living to talk about it.
BINARY I/O IN JAVA CSC 202 November What should be familiar concepts after this set of topics: All files are binary files. The nature of text files.
User Input ICS2O.
File Input / Output.
Introduction to programming in java
Reading from a file and Writing to a file
Objectives You should be able to describe: Interactive Keyboard Input
Strings and File I/O.
Computer Programming Methodology Files and Colors
Computer Science 3 Hobart College
Chapter 3 Assignment Statement
Computer Programming Methodology Input and While Loop
Computer Programming Methodology Luminance
I/O Basics.
Accessing Files in Java
I/O Streams- Basics Byte Streams and Character Streams
Chapter 2.
IDENTIFIERS CSC 111.
Java for Teachers Intermediate
مساق: خوارزميات ومبادئ البرمجة الفصل الدراسي الثاني 2016/2015
Introduction to Java Programming
An Introduction to Java – Part I, language basics
Chapter 2 Edited by JJ Shepherd
Introduction to Classes and Methods
Chapter 2: Java Fundamentals
The keyboard is the standard input device.
Primitive Types and Expressions
Chapter 2: Java Fundamentals cont’d
David Davenport Spring 2005
Presentation transcript:

Computer Programming Methodology File Input COS 130 Computer Programming Methodology File Input

Reading Binary Data Scanner class only reads text data – letters The ppm graphics files use binary data to save space. Therefore we will need some other way to read files. DataInputStream class will allow us to read binary data

DataInputStream This finds the library This makes some else import java.io.*; class myClass { public static void main (String args[]) throws IOException { DataInputStream reader = new DataInputStream(System.in); int id1 = reader.readUnsignedByte(); if (id1 == 'P') { //found a capital P // stuff } This makes some else deal with our problems Creates a DataInputStream Object This specifies the keyboard Or a redirected file This reads a byte

Convert char to int In the P6 file the width and height are stored as characters (letters) However, we will need to do math with them Specifically we will want to use them to decide how many pixels to read in.

Example convert char to int int number = 0; int datum = reader.readUnsignedByte(); while(Character.isWhitespace(datum)) { datum = reader.readUnsignedByte(); } while (Character.isDigit(datum)) { number= number * 10 + Character.getNumericValue(datum);

Casting Putting Big Things into Little Things Java attempts to protect you Example: double pi = 3.14; double r = 7; int result = pi * r * r; Will Not Compile! Putting a double (which is big) into an int will lose things

Casting Trust Me! I know what I am doing! double pi = 3.14; double r = 7; int result =(int) (pi * r * r); Cast operator Trust Me! I know what I am doing!

Example Make a color 10% brighter Will result in a double Giving a compile error red = red * 1.10 ; (int) ( )