Midterm Logistics. Midterm tonight, 7PM 10PM Exam location by last name:

Similar documents
Review from Last Time

Recitation 9 Stream and Phidget

Project #1 Computer Science 2334 Fall 2008

Project #1 rev 2 Computer Science 2334 Fall 2013 This project is individual work. Each student must complete this assignment independently.

Lecture 4: Exceptions. I/O

Inheritance E, xc Ex eptions ceptions I/O

Project 1 Computer Science 2334 Spring 2016 This project is individual work. Each student must complete this assignment independently.

I/O STREAM (REQUIRED IN THE FINAL)

Instructor: Craig Duckett. Lecture 04: Thursday, April 5, Relationships

Lab 5: Java IO 12:00 PM, Feb 21, 2018

How To Factory Reset Iphone 4 When Locked Out Without A Computer

CSE 374 Programming Concepts & Tools

Input from Files. Buffered Reader

CIT 590 Homework 10 Battleship

Hello, and welcome to another episode of. Getting the Most Out of IBM U2. This is Kenny Brunel, and

Outline. CIS 110: Introduction to Computer Programming. Exam announcements. Programming assertions revisited. An extended example: mystery

Exceptions in Java

Question 1. (2 points) What is the difference between a stream and a file?

============================================================================

Simple Java I/O. Part I General Principles

In this tutorial we are going to take a look at the CentovaCast 3 control panel running ShoutCast 2 and explain some of the basic features.

Java Input/Output. 11 April 2013 OSU CSE 1

CSE 143 Sp03 Midterm 2 Sample Solution Page 1 of 7. Question 1. (2 points) What is the difference between a stream and a file?

CS103 Spring 2018 Mathematical Vocabulary

Plex. From accessing plex to requests, check here for information and FAQ on all things Plex at TheMainframe

UI Review. The Good: Winamp

How to git with proper etiquette

CIS 110: Introduction to Computer Programming

Trying To Uninstall Norton 360 Wont Let Me Connect

Check out FilesAndExceptions from SVN. Exam 2 Review File I/O, Exceptions Vector Graphics Project

1.00 Lecture 30. Sending information to a Java program

CS 200 File Input and Output Jim Williams, PhD

Download, Install and Use Winzip

Git Source Control: For the Rest of Us. Nolan Erck

Networking Code CSCI 201 Principles of Software Development

Simple Java Input/Output

Samsung Galaxy S3 Repair Video Calling Not Working

Puma Energy elearning Hub. How To Guide for Staff Includes FAQs and Troubleshooting Guide

Slide 1 CS 170 Java Programming 1 The Switch Duration: 00:00:46 Advance mode: Auto

Question 0. (1 point) Write the correct ID of the section you normally attend on the cover page of this exam if you have not already done so.

I DO NOT OWN ITUNES OR ANYTHING IN THE THUMBNAIL THIS IS ALL OWNED BY APPLE.

Exceptions. References. Exceptions. Exceptional Conditions. CSE 413, Autumn 2005 Programming Languages

Announcements. CS18000: Problem Solving And Object-Oriented Programming

How To Add Songs To Iphone 4 Without Deleting Old Ones

Computer Without Deleting Old Ones

CS 201, Fall 2016 Sep 28th Exam 1

Synonyms. Hostile. Chilly. Direct. Sharp

PIC 20A Streams and I/O

Conveying Emotion. Chapter 12: Computers In Polite Society: Social Implications of IT. Improving the Effectiveness of . Problems with

Exceptions. CSE 142, Summer 2002 Computer Programming 1.

Exceptions. Readings and References. Exceptions. Exceptional Conditions. Reading. CSE 142, Summer 2002 Computer Programming 1.

Instructions For New Ios 7.1 Features Ipad Mini >>>CLICK HERE<<<

HST 952. Computing for Biomedical Scientists Lecture 8

ITunes. itunes works with Windows 2000, XP, Windows Server 2003, Mac OS X and it also works on a few cellular phones.

B - Broken Track Page 1 of 8

Out for Shopping-Understanding Linear Data Structures English

Object-Oriented Programming Design. Topic : Streams and Files

Section Solutions 8. /* The separator used to delimit the start and end of a flight. */ private static final String FLIGHT_DELIMITER = " -> ";

JAC444 - Lecture 4. Segment 1 - Exception. Jordan Anastasiade Java Programming Language Course

Outline for Today. How can we speed up operations that work on integer data? A simple data structure for ordered dictionaries.

Computer Using A Flash Drive

COMP 213. Advanced Object-oriented Programming. Lecture 20. Network Programming

Back to the main page Back to the Tutorial Page Digital Audio Rules of Audacity Setup, Audio Import and Playback Recording with Audacity

Handout 4: Version Control Reference

Wednesday. Wednesday, September 17, CS 1251 Page 1

You must define a class that represents songs. Your class will implement the Song interface in $master/proj2/cs61b/song.java.

Manually Sync App Itunes Iphone Without >>>CLICK HERE<<<

Post Experiment Interview Questions

Turing Machines Part Two

Question 1. [5 points] What output is printed by the following program (which begins on the left and continues on the right)?

Defensive Programming. Ric Glassey

MITOCW watch?v=0jljzrnhwoi

mismatch between what is maybe possible today and what is going on in many of today's IDEs.

Instructor (Mehran Sahami):

The following content is provided under a Creative Commons license. Your support

09-1. CSE 143 Java GREAT IDEAS IN COMPUTER SCIENCE. Overview. Data Representation. Representation of Primitive Java Types. Input and Output.

16-Dec-10. Consider the following method:

Department of Electrical Engineering and Computer Sciences Spring 2001 Instructor: Dan Garcia CS 3 Midterm #2. Personal Information

Screenshots Made Easy

IT101. File Input and Output

CS Week 11. Jim Williams, PhD

CSE 143 Au04 Midterm 2 Sample Solution Page 1 of 7

CISC 323 (Week 9) Design of a Weather Program & Java File I/O

BBC Learning English 6 Minute English Work s

Software Practice 1 - File I/O

Manual Of Ios 7 Beta 3 Iphone 5 >>>CLICK HERE<<<

Welcome to the world of .

Earthwork 3D for Dummies Doing a digitized dirt takeoff calculation the swift and easy way

CSPP : Introduction to Object-Oriented Programming

PROFESSOR: Last time, we took a look at an explicit control evaluator for Lisp, and that bridged the gap between

MCSA Windows Server 2012 R2 Complete Study Guide: Exams , , , And PDF

Backup using Carbon Copy Cloner

HELPLINE. Dilwyn Jones

Itunes Manually Delete Songs From Iphone 4 >>>CLICK HERE<<<

Exceptions. Produced by. Introduction to the Java Programming Language. Eamonn de Leastar

Chapter 12. File Input and Output. CS180-Recitation

Ipod Touch Password Manual 4th Generation. Repair Service >>>CLICK HERE<<<

Introduction to Prof. Clarkson Fall Today s music: Prelude from Final Fantasy VII by Nobuo Uematsu (remastered by Sean Schafianski)

Multiplayer Game Programming 2/26

Today. Book-keeping. File I/O. Subscribe to sipb-iap-java-students. Inner classes. Debugging tools

Transcription:

File Processing

Midterm Logistics Midterm tonight, 7PM 10PM Exam location by last name: Last names starts with A-J: Hewlett 200 Last names starts with K-O: Braun Auditorium Last names starts with P-S: Gates B01 Last names starts with T-Z: Gates B03

Welcome to Big Data

Getting Data Into Programs Put it directly in the program: Define constants holding your values. Get it from the user: Mouse events, readline, etc. Generate it randomly: Use a RandomGenerator. Get it from an external source. Store it in a file and read it later.

Reading Files Virtually all programs that you've used at some point read files from disk: Word processing (documents) Eclipse (Java files) Web browser (cookies) IM client (stored login information) Games (saved progress) Music player (songs)

The Structure of Files A file is just a series of bits (ones and zeros). Those bits can have structure: Plain-text: Bits represent characters. JPEG: Bits encode information about the structure of an image. MP3: Bits encode frequency information about music. etc.

The Structure of Files A file is just a series of bits (ones and zeros). Those bits can have structure: Plain-text: Bits represent characters. JPEG: Bits encode information about the structure of an image. MP3: Bits encode frequency information about music. etc.

Step one: Open the file for reading.

To use the BufferedReader and FileReader types, you need to import java.io.*;

Step Two: Read the file, one line at a time.

String line1 = br.readline();

String line1 = br.readline();

String line1 = br.readline(); // Yesterday, upon the stair,

String line1 = br.readline(); // Yesterday, upon the stair,

String line1 = br.readline(); // Yesterday, upon the stair, String line2 = br.readline();

String line1 = br.readline(); // Yesterday, upon the stair, String line2 = br.readline();

String line1 = br.readline(); // Yesterday, upon the stair, String line2 = br.readline(); // I met a man who wasn't there

String line1 = br.readline(); // Yesterday, upon the stair, String line2 = br.readline(); // I met a man who wasn't there

String line1 = br.readline(); // Yesterday, upon the stair, String line2 = br.readline(); // I met a man who wasn't there String line3 = br.readline();

String line1 = br.readline(); // Yesterday, upon the stair, String line2 = br.readline(); // I met a man who wasn't there String line3 = br.readline();

String line1 = br.readline(); // Yesterday, upon the stair, String line2 = br.readline(); // I met a man who wasn't there String line3 = br.readline(); // He wasn't there again today

String line1 = br.readline(); // Yesterday, upon the stair, String line2 = br.readline(); // I met a man who wasn't there String line3 = br.readline(); // He wasn't there again today

String line1 = br.readline(); // Yesterday, upon the stair, String line2 = br.readline(); // I met a man who wasn't there String line3 = br.readline(); // He wasn't there again today String line4 = br.readline();

String line1 = br.readline(); // Yesterday, upon the stair, String line2 = br.readline(); // I met a man who wasn't there String line3 = br.readline(); // He wasn't there again today String line4 = br.readline();

String line1 = br.readline(); // Yesterday, upon the stair, String line2 = br.readline(); // I met a man who wasn't there String line3 = br.readline(); // He wasn't there again today String line4 = br.readline(); // I wish, I wish he'd go away...

String line1 = br.readline(); // Yesterday, upon the stair, String line2 = br.readline(); // I met a man who wasn't there String line3 = br.readline(); // He wasn't there again today String line4 = br.readline(); // I wish, I wish he'd go away...

String line1 = br.readline(); // Yesterday, upon the stair, String line2 = br.readline(); // I met a man who wasn't there String line3 = br.readline(); // He wasn't there again today String line4 = br.readline(); // I wish, I wish he'd go away... String line5 = br.readline();

String line1 = br.readline(); // Yesterday, upon the stair, String line2 = br.readline(); // I met a man who wasn't there String line3 = br.readline(); // He wasn't there again today String line4 = br.readline(); // I wish, I wish he'd go away... String line5 = br.readline();

String line1 = br.readline(); // Yesterday, upon the stair, String line2 = br.readline(); // I met a man who wasn't there String line3 = br.readline(); // He wasn't there again today String line4 = br.readline(); // I wish, I wish he'd go away... String line5 = br.readline(); //

String line1 = br.readline(); // Yesterday, upon the stair, String line2 = br.readline(); // I met a man who wasn't there String line3 = br.readline(); // He wasn't there again today String line4 = br.readline(); // I wish, I wish he'd go away... String line5 = br.readline(); //

String line1 = br.readline(); // Yesterday, upon the stair, String line2 = br.readline(); // I met a man who wasn't there String line3 = br.readline(); // He wasn't there again today String line4 = br.readline(); // I wish, I wish he'd go away... String line5 = br.readline(); // String line6 = br.readline();

String line1 = br.readline(); // Yesterday, upon the stair, String line2 = br.readline(); // I met a man who wasn't there String line3 = br.readline(); // He wasn't there again today String line4 = br.readline(); // I wish, I wish he'd go away... String line5 = br.readline(); // String line6 = br.readline(); // *Returns null*

String line1 = br.readline(); // Yesterday, upon the stair, String line2 = br.readline(); // I met a man who wasn't there String line3 = br.readline(); // He wasn't there again today String line4 = br.readline(); // I wish, I wish he'd go away... String line5 = br.readline(); // String line6 = br.readline(); // *Returns null* Step Three: Close the file.

String line1 = br.readline(); // Yesterday, upon the stair, String line2 = br.readline(); // I met a man who wasn't there String line3 = br.readline(); // He wasn't there again today String line4 = br.readline(); // I wish, I wish he'd go away... String line5 = br.readline(); // String line6 = br.readline(); // *Returns null* br.close();

Let's Try It Out!

There's a Catch...

Sometimes Things Break Programs sometimes encounter unexpected errors. Sometimes these are bugs: Dividing by zero. Sending a message to a null object. Sometimes these are due to external factors: Network errors. Missing files.

Exceptional Cases If Java encounters a case where it can't proceed as normal, it will cause an exception. Java requires that your program handle certain types of exceptions. Think of exceptions as rerouting control in an emergency: If all goes well, program continues as usual. If something goes wrong, handle the emergency.

Let's Try It Out!

Let's try It Out!

try-ing Your Best To use a method or class that might cause an exception, you need to tell Java to try its best, knowing that it might fail.

try-ing Your Best To use a method or class that might cause an exception, you need to tell Java to try its best, knowing that it might fail. String line1 = br.readline(); // Yesterday, upon the stair, String line2 = br.readline(); // I met a man who wasn't there String line3 = br.readline(); // He wasn't there again today String line4 = br.readline(); // I wish, I wish he'd go away... String line5 = br.readline(); // String line6 = br.readline(); // *Returns null* br.close();

try-ing Your Best To use a method or class that might cause an exception, you need to tell Java to try its best, knowing that it might fail. try { String line1 = br.readline(); // Yesterday, upon the stair, String line2 = br.readline(); // I met a man who wasn't there String line3 = br.readline(); // He wasn't there again today String line4 = br.readline(); // I wish, I wish he'd go away... String line5 = br.readline(); // String line6 = br.readline(); // *Returns null* } br.close();

There's a Catch...

There's a catch...

try and catch me If an exception occurs, you may need to tell Java to catch that exception.

try and catch me If an exception occurs, you may need to tell Java to catch that exception. try { String line1 = br.readline(); // Yesterday, upon the stair, String line2 = br.readline(); // I met a man who wasn't there String line3 = br.readline(); // He wasn't there again today String line4 = br.readline(); // I wish, I wish he'd go away... String line5 = br.readline(); // String line6 = br.readline(); // *Returns null* } br.close();

try and catch me If an exception occurs, you may need to tell Java to catch that exception. try { String line1 = br.readline(); // Yesterday, upon the stair, String line2 = br.readline(); // I met a man who wasn't there String line3 = br.readline(); // He wasn't there again today String line4 = br.readline(); // I wish, I wish he'd go away... String line5 = br.readline(); // String line6 = br.readline(); // *Returns null* br.close(); } catch (IOException e) { println("an error occurred: " + e); }

try and catch me If an exception occurs, you may need to tell Java to catch that exception. try { String line1 = br.readline(); // Yesterday, upon the stair, String line2 = br.readline(); // I met a man who wasn't there String line3 = br.readline(); // He wasn't there again today String line4 = br.readline(); // I wish, I wish he'd go away... String line5 = br.readline(); // String line6 = br.readline(); // *Returns null* br.close(); } catch (IOException e) { println("an error occurred: " + e); } If something fails up here

try and catch me If an exception occurs, you may need to tell Java to catch that exception. try { If something fails up here String line1 = br.readline(); // Yesterday, upon the stair, String line2 = br.readline(); // I met a man who wasn't there String line3 = br.readline(); // He wasn't there again today String line4 = br.readline(); // I wish, I wish he'd go away... String line5 = br.readline(); // String line6 = br.readline(); // *Returns null* br.close(); } catch (IOException e) { println("an error occurred: " + e); } we immediately jump down here.

Finally... let's make this program work!

Reading a File The idiomatic read all the lines of a file code is shown here: try { /* open the file */ while (true) { String line = br.readline(); if (line == null) break; /* process line */ } br.close(); } catch (IOException e) { /* handle error */ }

Writing to Files Writing to files is conceptually similar to reading files. Open the file for writing (using PrintWriter instead of BufferedReader). Write the contents you'd like to the file. Close the file.

/ / / / / / DANGER \ \ \ \ \ Writing to an existing file will permanently overwrite the contents of that file. Don't write to a file unless you're okay setting it on fire!

Putting Everything Together

http://2.bp.blogspot.com/_xqlf69h4gxa/tlvwfxdmxni/aaaaaaaaazu/9lwr-2smzmc/s1600/empty+fridge.jpg