Download presentation
Presentation is loading. Please wait.
1
SE-1021 Software Engineering II
7/29/2018 SE-1021 Software Engineering II Week 9, Day 2 Exceptions (briefly) Files Bits and Bytes Week 9, Day 3 Lab 8 Complete Demo Lab 9: Start writing/reading bmsoe files SE-1021 Dr. Josiah Yoder Slide style: Dr. Hornick Dr. Josiah Yoder
2
To catch individually, what order?
Exception IllegalArgumentException IOException NumberFormatException RuntimeException SE-1021 Dr. Josiah Yoder Slide style: Dr. Hornick
3
Slide style: Dr. Hornick
… } catch ( ) { } catch ( ) { } SE-1021 Dr. Josiah Yoder Slide style: Dr. Hornick
4
Slide style: Dr. Hornick
Review / New Material How many bits are there in a byte? Write all the three-bit binary numbers. How many values can you encode with a single byte? SE-1021 Dr. Josiah Yoder Slide style: Dr. Hornick
5
Slide style: Dr. Hornick
ASCII table First digit LF – Line feed (\n) 0x0A CR – carriage return (\r) 0x0D Second digit SE-1021 Dr. Josiah Yoder Slide style: Dr. Hornick
6
Slide style: Dr. Hornick
ASCII How many bytes do you need to store one ASCII character? How many bits do you need to store one ASCII character? SE-1021 Dr. Josiah Yoder Slide style: Dr. Hornick
7
Slide style: Dr. Hornick
Files A file is a container for a sequence of bytes stored on the computer’s hard drive Each byte is made up of 8 bits An ASCII character is one way of storing letters. “Plain text files” often use ANSI ASCII encoding. To encode other languages, we need to use a different encoding. SE-1021 Dr. Josiah Yoder Slide style: Dr. Hornick
8
Slide style: Dr. Hornick
Using files in Java Both files and folders (Directories) are represented with a “Path” object as discussed earlier We can open the file to get the byte stream (Coding example) Path path = Paths.get(…); boolean isDir = Files.isDirectory(path); SE-1021 Dr. Josiah Yoder Slide style: Dr. Hornick
9
Reading the bytes from a file
InputStream is an abstract class to represent reading bytes FileInputStream is a class that reads bytes from a file You can also get input streams to read bytes from the network, a byte array, etc. Use inputStream.read() to read one byte Returns -1 (an integer) if the byte is not read Use inputStream.read(…) to read multiple bytes at a time SE-1021 Dr. Josiah Yoder Slide style: Dr. Hornick
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.