Presentation is loading. Please wait.

Presentation is loading. Please wait.

Hey, Remember Java? Part 2 Written by J.J. Shepherd.

Similar presentations


Presentation on theme: "Hey, Remember Java? Part 2 Written by J.J. Shepherd."— Presentation transcript:

1 Hey, Remember Java? Part 2 Written by J.J. Shepherd

2

3 File I/O Reading from a file works much like reading from the keyboard using a Scanner Concept Must be in a try-catch block Must close the stream at the end Scanner inputStream = new Scanner( new File(“./turtles.txt”)); int turtleAmt = inputStream.nextInt(); inputStream.close();

4 File I/O Writing to a file works much like System.out Concept for setting up Must be in a try-catch block Must close the file at the end PrintWriter outputStream = new PrintWriter( new FileOutputstream(fileName, true)); outputStream.println(“Hello World”); outputStream.close();

5 String Manipulation Used heavily in File I/O and throughout this course This is used to analyze and potentially modify strings

6 String Manipulation Use the methods in the following slides to assist The only one that is missing is.contains which will return a true or false value depending if the string contains that string anywhere More information on strings can be found in the javadoc https://docs.oracle.com/javase/7/docs/api/java/ lang/String.html

7

8

9 String Manipulation When in doubt… Read it character by character using charAt If you truly do not understand regular expressions (REGEX’s) then avoid using methods that use them

10


Download ppt "Hey, Remember Java? Part 2 Written by J.J. Shepherd."

Similar presentations


Ads by Google