Chapter 12 – Part 3 Dr. Clincy ------ Lecture.

Slides:



Advertisements
Similar presentations
Chapter 6 Server-side Programming: Java Servlets
Advertisements

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.
1 Strings and Text I/O. 2 Motivations Often you encounter the problems that involve string processing and file input and output. Suppose you need to write.
Liang, Introduction to Java Programming, Eighth Edition, (c) 2011 Pearson Education, Inc. All rights reserved Chapter 9 Strings and Text I/O.
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.
Slides prepared by Rose Williams, Binghamton University Chapter 10 File I/O.
The Internet & The World Wide Web Notes
2. I/O Text Files CCSA225 - Advanced Java Programming Sarah Alodan
Liang, Introduction to Java Programming, Tenth Edition, (c) 2015 Pearson Education, Inc. All rights reserved. 1 Chapter 12 Exception Handling and Text.
© Copyright 2012 by Pearson Education, Inc. All Rights Reserved. Chapter 13 Files and Exception Handling 1.
5 Chapter Five Web Servers. 5 Chapter Objectives Learn about the Microsoft Personal Web Server Software Learn how to improve Web site performance Learn.
1 Introduction to Java Brief history of Java Sample Java Program Compiling & Executing Reading: => Section 1.1.
Chapter 7 Input/ and Exception Handling. The String Class A string is a sequence of characters. In many languages, strings are treated as an array of.
Floating point numerical information. Previously discussed Recall that: A byte is a memory cell consisting of 8 switches and can store a binary number.
Programming Fundamentals I (COSC- 1336), Lecture 6 (prepared after Chapter 9 of Liang’s 2011 textbook) Stefan Andrei 11/24/20151 COSC-1336, Lecture 6.
CMSC 202 Text File I/O. Aug 8, Text Files and Binary Files Files that are designed to be read by human beings, and that can be read or written with.
1 Chapter 9 Strings and Text I/O. 2 Objectives F To use the String class to process fixed strings. F To use the Character class to process a single character.
COP3502 Programming Fundamentals for CIS Majors 1 Instructor: Parisa Rashidi.
Reading input from the console input. Java's console input The console is the terminal window that is running the Java program I.e., that's the terminal.
Liang, Introduction to Java Programming, Sixth Edition, (c) 2007 Pearson Education, Inc. All rights reserved File I/O in java chapter.
CS 112 Programming 2 Lecture 08 Exception Handling & Text I/O (1)
COMP 110: Spring Announcements Program 5 Milestone 1 was due today Program 4 has been graded.
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.
How to search and how to upload files into sentry file
4.01 How Web Pages Work.
4.01 How Web Pages Work.
Chapter 2 Clarifications
File Input / Output.
CMSC 202 Text File I/O.
Reading from a file and Writing to a file
CS 3501 Final Project Instructions
Content Programming Overview The JVM A brief look at Structure
EE2E1. JAVA Programming Revision Lecture.
Use of ICT in Education for Online and Blended Learning
CHAPTER 5 JAVA FILE INPUT/OUTPUT
I/O Basics.
Chapter 12 Exception Handling and Text IO
HIGHLEVEL REVIEW Chapter 9 Objects and Classes
CSS161: Fundamentals of Computing
CS Week 11 Jim Williams, PhD.
CS 200 File Input and Output
CS 6021 Advance Architecture Project
Chapter 17 Binary I/O Dr. Clincy - Lecture.
Chapter 10 Thinking in Objects
CS6021 Final Project – Team Part
Chapter 12 Exception Handling and Text IO
Chapter 9 Strings and Text I/O
CS 3501 Final Project Instructions
Text I/O.
Unit-2 Objects and Classes
File I/O ICS 111: Introduction to Computer Science I
Dr. Clincy Professor of CS
Chapter 12 Exception Handling and Text IO
Web Page Concept and Design :
File Handling in Java January 19
CS Chapter 3 (3A and ) Review
Dr. Clincy Professor of CS
CS Chapter 3 (3A and ) Review
Introduction to Java Brief history of Java Sample Java Program
Lecture Notes - Week 2 Lecture-1. Lecture Notes - Week 2 Lecture-1.
CS Chapter 3 (3A and ) Review
Object Oriented Programming in java
Dr. Clincy Professor of CS
Chapter 9 Strings and Text I/O
Chapter 12 Exception Handling and Text IO Part 2
4.01 How Web Pages Work.
Information Retrieval and Web Design
4.01 How Web Pages Work.
Chapter 12 Exception Handling and Text IO
CS18000: Problem Solving and Object-Oriented Programming
Presentation transcript:

Chapter 12 – Part 3 Dr. Clincy ------ Lecture

The File Class Up to this point, you have entered data into your program from a prompt – the data is temporary and lost after the program terminates. To permanently store the data for the program, it needs to be saved in a file. A file can be transported and read later by other programs. So the File class is introduced – useful for (1) obtaining file/directories properties, (2) deleting files/directories, (3) renaming files/directories, and (4) creating files/directories BTW: a filename is a string .. and the full or absolute filename contains a filename with its complete path and drive letter. For example: C:\\ksuweb\vclincy\1302.html For the relative file name, the directory path is omitted. ie. 1302.html The File class DOES NOT contain methods for reading and writing file content The File class is a wrapper class for the file name and its directory path. Dr. Clincy ------ Lecture

The File Class The File class is a wrapper class for the file name and its directory path. RECALL: A wrapper class is any class that “encapsulates” (or wrap) the functionality of another class. Example: new File (“c\\book”) creates a File object for the directory c:\\book Example: new File (“c:\\book\\test.dat”) creates a File object for the file c:\book\test.dat Once the object is created, various methods can be used Dr. Clincy ------ Lecture

Obtaining File Properties and Manipulating File Dr. Clincy ------ Lecture

Example: Using File Class Methods 1 public class TestFileClass { 2 public static void main(String[] args) { 3 java.io.File file = new java.io.File("image/us.gif"); 4 System.out.println("Does it exist? " + file.exists()); 5 System.out.println("The file has " + file.length() + " bytes"); 6 System.out.println("Can it be read? " + file.canRead()); 7 System.out.println("Can it be written? " + file.canWrite()); 8 System.out.println("Is it a directory? " + file.isDirectory()); 9 System.out.println("Is it a file? " + file.isFile()); 10 System.out.println("Is it absolute? " + file.isAbsolute()); 11 System.out.println("Is it hidden? " + file.isHidden()); 12 System.out.println("Absolute path is " + 13 file.getAbsolutePath()); 14 System.out.println("Last modified on " + 15 new java.util.Date(file.lastModified())); 16 } 17 } Dr. Clincy ------ Lecture

Text I/O As mentioned, a File object encapsulates the properties of a file or a path, but does not contain the methods for reading/writing data from/to a file. In order to perform I/O, you need to create objects using appropriate Java I/O classes. The proper objects contain the methods for reading/writing data from/to a file. The Scanner class is used for reading text data from a file. (java.util.Scanner) The PrintWriter class is used for creating a file and writing text data to a file. (java.io.PrintWriter) PrintWriter someoutput = new PrintWriter (somefilename) Now print, println and printf can be used to write data to the file Dr. Clincy ------ Lecture

Writing Data Using PrintWriter Dr. Clincy ------ Lecture

Dr. Clincy ------ Lecture

Dr. Clincy ------ Lecture

Reading Data Using Scanner ReadData Run Dr. Clincy ------ Lecture

Reading Data from the Web Just like you can read data from a file on your computer, you can read data from a file on the Web if you know the file’s URL (Uniform Resource Locator – unique address for the file). (1) When you enter the URL in your browser (2) The web server sends the data to your browser – which displays graphically Dr. Clincy ------ Lecture

Project 1 Difference between a project versus a lab: Work within team (no help outside of team). Mostly cover concepts already covered in the lab assignments. Bulk of the work is expected to done outside of class time. Will pay more attention to “how” the program is developed. Will pay more attention to the “quality” of the program. Will pay more attention to pre-development work: design and team work OBJECTIVE: You will create a program as a team based on some specs, give a presentation on how the program was built, and demonstrate the program in real-time. You will work in teams of 5 to 6 The program is due Monday, Feb 19th at 12pm – upload java files, UML diagrams, and powerpoint slides to DL2 – no need to upload screen shots because you will explain and demo your program on Monday (Feb 19th) during class time Your presentation on Monday (2/19/18) should be 15 minutes – penalty per minutes over or under – team decision on how to handle this – your minutes entails a 10-minute ppt presentation and 5-minute program run and test. The Professor will dictate the testing part of your program – you will only be able to run the code uploaded to D2L. Steps: Meet and Scope out work, Design, Allocate Work, Build program as a team, Test the program, and Prepare Presentation Dr. Clincy ------ Lecture

Presentation Your presentation on Monday (2/19/18) should be 15 minutes – penalty per minutes over or under 15 minutes – team decision on how to handle this – your minutes entails a 10-minute ppt presentation and 5-minute program run and test. Every team member must present an equal amount of time. Your presentation should answer the following questions: Does the program fully run and satisfies the specs completely ? If not, what is missing ? Explain the design of your program via UML diagrams and flow charts. Explain why your program is efficient or not. Explain what exception handling was incorporated and why and where. Explain what superclass(es)-subclass(es) was (were) used and why. Explain any negative issues or problems the team may have encountered in working as team in building the program – and if those issues were remedied, how ? Regarding the program test – you will only be able to run the program uploaded to D2L. By doing so, all teams will have had the same deadline. Dr. Clincy ------ Lecture

PROJECT 1 TEAMS As a team member, you are responsible for contacting team mates that did not attend class for the Project Rollout – and responsible for getting them up to speed regarding the project requirements and expectations. Dr. Clincy ------ Lecture