Announcements Quiz 2 Grades Posted on blackboard.

Slides:



Advertisements
Similar presentations
Continuation of chapter 6…. Nested while loop A while loop used within another while loop is called nested while loop. Q. An illustration to generate.
Advertisements

CSCI S-1 Section 5. Deadlines for Problem Set 3 Part A – Friday, July 10, 17:00 EST Parts B – Tuesday, July 14, 17:00 EST Getting the code examples from.
 We can use a combination of the File and FileOutputStream to write a series of bytes to a file.
1 CS 105 Lecture 9 Files Version of Mon, Mar 28, 2011, 3:13 pm.
Java Intro. Strings “This is a string.” –Enclosed in double quotes “This is “ + “another “ + “string” –+ concatenates strings “This is “ “ string”
Reading Information From the User Making your Programs Interactive.
File I/O There’s more to life than the keyboard. Interactive vs. file I/O All of the programs we have seen or written thus far have assumed interaction.
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.
File Review Declare the File Stream Object Name –ofstream for output to file –ifstream for input from file Associate a File Name with the File Stream Object.
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.
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 ->
LAB 10.
2-1 CM0551 Week 3 The scanner class – file input A Spelling Checker Time and space requirements for various dictionary structures.
Using java’s Scanner class To read from input and from a file. (horstmann ch04 and ch 17)
Computer Programming Lab(5).
Input / Output Chapter 13.  We use files all the time  Programs are files  Documents are files  We want them to be “permanent”  To last beyond execution.
Lecture 10 Instructor: Craig Duckett Lecture 10 is in Lecture 11 Folder.
Java Fundamentals 3 Input and Output statements. Standard Output Window Using System.out, we can output multiple lines of text to the standard output.
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.
Input & Output In Java. Input & Output It is very complicated for a computer to show how information is processed. Although a computer is very good at.
Chapter 10 Exceptions. Chapter Scope The purpose of exceptions Exception messages The call stack trace The try-catch statement Exception propagation The.
CSCI S-1 Section 6. Coming Soon Homework Part A – Friday, July 10, 17:00 EST Homework Part B – Tuesday, July 14, 17:00 EST Mid-Term Quiz Review – Friday,
CSC 1051 – Data Structures and Algorithms I Dr. Mary-Angela Papalaskari Department of Computing Sciences Villanova University Course website:
***** SWTJC STEM ***** Chapter 3-1 cg 39 Math Class The Math class provides a convenient way to access higher math functions. The Math class is automatically.
CSC 1051 – Data Structures and Algorithms I Dr. Mary-Angela Papalaskari Department of Computing Sciences Villanova University Course website:
CHAPTER 5 GC 101 Input & Output 1. INTERACTIVE PROGRAMS  We have written programs that print console output, but it is also possible to read input from.
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.
Quiz 2 Results. What Is Wrong? #include using namespace std int Main() { // Say Hello 4 times for(i == 0; i < 3; i++) { cout >> "Hello World!"
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.
Mark Fontenot CSE Honors Principles of Computer Science I Note Set 15.
 Learn about computer files  Use the Path class  Learn about  Streams  Buffers  file organization  Use Java’s IO classes to write to and read from.
Files Review For output to a file: –FileOutputStream variable initialized to filename (String) and append/not append (boolean) –PrintWriter variable initialized.
Computer Programming Lab 9. Exercise 1 Source Code package excercise1; import java.util.Scanner; public class Excercise1 { public static void main(String[]
import java.util.Scanner; class myCode { public static void main(String[] args) { Scanner input= new Scanner(System.in); int num1; System.out.println(“Enter.
Exam 2 EXAM 2 Thursday!!! 25% of Final Grade Know: loops, switch/case Files Input failure (e.g. scan.hasNextInt())
CS 115 OBJECT ORIENTED PROGRAMMING I LECTURE 6_1 GEORGE KOUTSOGIANNAKIS Copyright: FALL 2015 Illinois Institute of Technology- George Koutsogiannakis 1.
A.P. Computer Science Input is NOT tested on the AP exam, but if we want to do any labs, we need input!!
File Input & Output Sections Outcomes  Know the difference between files and streams  Use a Scanner to read from a file  add “throws” annotations.
1 Text File Input and Output. Objectives You will be able to Write text files from your Java programs. Read text files in your Java programs. 2.
Introduction to programming in java
For Friday Finish reading chapter 9 WebCT quiz 17.
Chapter 2 Clarifications
File I/O CLI: File Input CLI: File Output GUI: File Chooser
Introduction to programming in java
CSC1401 Input and Output (and we’ll do a bit more on class creation)
using System; namespace Demo01 { class Program
Strings and File I/O.
Maha AlSaif Maryam AlQattan
File Input and Output TOPICS File Input Exception Handling File Output.
Interactive Standard Input/output
Computer Programming Methodology Input and While Loop
TK1114 Computer Programming
Quiz Next Monday.
Something about Java Introduction to Problem Solving and Programming 1.
Some File I/O CS140: Introduction to Computing 1 Savitch Chapter 9.1, 10.1, /25/13.
I/O Streams- Basics Byte Streams and Character Streams
File Input and Output TOPICS File Input Exception Handling File Output.
הרצאה 12: קבצים וחריגות (Exceptions)
Exceptions Exception handling is an important aspect of object-oriented design Chapter 10 focuses on the purpose of exceptions exception messages the.
Introduction to Classes and Methods
September 9, 2008 Lecture 5 – More IO.
Know for Quiz Everything through Last Week and Lab 7
Exam 2 EXAM 2 Thursday!!! 25% of Final Grade
class PrintOnetoTen { public static void main(String args[]) {
September 9, 2008 Lecture 5 – More IO.
Module 4 Loops and Repetition 4/7/2019 CSE 1321 Module 4.
CSC1401 Input and Output (with Files)
មជ្ឈមណ្ឌលកូរ៉េ សហ្វវែរ អេច អ ឌី
Presentation transcript:

Announcements Quiz 2 Grades Posted on blackboard

Files Data in Main Memory is “volatile” File: Place for “permanent” data storage C: drive, A: drive, Flash drive, etc. Disk File Main Memory main() int num; string firstname;

Scanner Input Scanner scan = new Scanner(System.in); while (scan.hasNextInt()) { i = scan.nextInt(); } // System.in is the keyboard “file”

Input Files import java.io.*; import java.util.Scanner; class FileInput { public static void main(String [ ] args) throws IOException { File ifile = new File("data.txt"); Scanner scan = new Scanner(ifile); while (scan.hasNextInt()) { i = scan.nextInt(); } data.txt file

Display Output for (i=0;i < 100; i = i + 2) { System.out.println(i); } // System.out is the display window “file”

Output File Streams import java.io.*; class FileOutput { public static void main(String [ ] args) throws IOException { int i; FileOutputStream ofile = new FileOutputStream("data2.txt",false); //true:APP PrintWriter pw = new PrintWriter(ofile); for (i=0;i < 100; i = i + 2) { pw.println(i); } pw.close(); // Writes data to file on disk }} 0 2 … 98 data2.txt

import java.util.Scanner; import java.io.*; class FormatFileData { public static void main(String [ ] args) throws IOException { int loops, integer, i; float decimal; String name; File ifile = new File("mydata.txt"); Scanner scan = new Scanner(ifile); loops = scan.nextInt(); for(i= 0 ; i < loops; i++) { integer = scan.nextInt(); decimal = scan.nextFloat(); name= scan.next(); System.out.print(integer + " "); System.out.print(decimal + " "); System.out.print(name + " "); System.out.println(); } mydata.txt file Jon Bill e9 Mary Smith -3 -4e3 xyz Jon Bill E10 Mary Smith -3 – xyz Output: