Lecture An introduction to computer science using java (2nd Edition): Chapter 15 - S.N. Kamin, D. Mickunas, E. Reingold

Chapter 15 - Text processing and file Input/Output. In this chapter we will: describe the package, introduce the Java StringBuffer class, show how files can be read and written, discuss how to handle file input and output exceptions, demonstrate how to perform console input and output. | Chapter 15 Text Processing and File Input/Output Lecture Slides to Accompany An Introduction to Computer Science Using Java (2nd Edition) by . Kamin, D. Mickunas, E. Reingold Chapter Preview In this chapter we will: describe the package introduce the Java StringBuffer class show how files can be read and written discuss how to handle file input and output exceptions demonstrate how to perform console input and output Strings Java provides a number of methods for operating on String objects String objects are immutable Immutable objects cannot be changed once they are created StringBuffer Java provides a mutable staring class called StringBuffer that allows strings to grow dynamically during program execution Several StringBuffer methods are the same as those found in String To convert between String objects and StringBuffer objects Java provides constructors for each class The StringBuffer class also contains a ToString method to allow easier output Sequential Files Files are stored are stored on disks In this section we will assume that files consist of multiple lines composed of characters Each line ends with an end of line character The file itself may have an end of file character Programmers often need to read or write files stored on disks File Input Java classes that support file input are found in the package FileReader allows us to open a file for reading BufferedReader is a wrapper class that provides methods that allow us to treat the file as a stream of characters increases the efficiency of reading allows line-oriented reading Wrapper Classes Class W is said to wrap class Y if: Y is a concrete (not abstract) class W’s constructor takes Y as an argument and stores a local copy of Y W reimplements all of Y’s methods A wrapper can wrap a class and be the subclass of another class at the same time Buffered Input We can make a file available for reading one character at a time by using FileReader fr = FileReader(filename); We can read the | Chapter 15 Text Processing and File Input/Output Lecture Slides to Accompany An Introduction to Computer Science Using Java (2nd Edition) by . Kamin, D. Mickunas, E. Reingold Chapter Preview In this chapter we will: describe the package introduce the Java StringBuffer class show how files can be read and written discuss how to handle file input and output exceptions demonstrate how to perform console input and output Strings Java provides a number of methods for operating on String objects String objects are immutable Immutable objects cannot be changed once they are created StringBuffer Java provides a mutable staring class called StringBuffer that allows strings to grow dynamically during program execution Several StringBuffer methods are the same as those found in String To convert between String objects and StringBuffer objects Java provides constructors for each class The StringBuffer class also contains a ToString method to allow easier output Sequential Files Files .

Không thể tạo bản xem trước, hãy bấm tải xuống
TỪ KHÓA LIÊN QUAN
TÀI LIỆU MỚI ĐĂNG
Đã phát hiện trình chặn quảng cáo AdBlock
Trang web này phụ thuộc vào doanh thu từ số lần hiển thị quảng cáo để tồn tại. Vui lòng tắt trình chặn quảng cáo của bạn hoặc tạm dừng tính năng chặn quảng cáo cho trang web này.