File Input and output

अब Quizwiz के साथ अपने होमवर्क और परीक्षाओं को एस करें!

write the code segment that uses a while loop to with a sentinel value that must be greater than 0

** in the text file after the last grade the programmer MUST type in a sentinel value of -1**

What class to we use to read data from a file

Scanner

how is the Scanner class used with files

Scanner class is used for reading text data from a file and the PrintWriter class for writing text data to a file

Create a program that copies all of the information from one file and creates a new file and then prints all of that information into that file

This file uses the printWrite to create a new file called "outs.txt. " then it writes all the information from grades1, into that outs.txt

What is a token

Token, is an individual item that is a string of characters separated by delimiters or white space.

how could the above code be handled if you did not know how many scores would be used in the project?

a sentinel vale -1 could be added to the input file 70 60 75 -1

how does the PrintWriter work? and what is the syntax for creating a PrintWriter object ?

can be used to create a file and write data to a text file. first you need to create a PrintWriter object for a text file as follows. then you can invoke print, println, printf methods on the PrintWriter object to write data to a file .

Exam1 Exam2 71 95 60 80 75 76 find the average score of both sets, notice the first line is not an integer

since the first 2 items are not int score the must be extracted using the "next" method instead of the nextInt and assigned to the String variables to be output later ** let it be noted that the computer does read the text file line by line left to right

how can you use the printWriter to use an existing file in which you just want to add information to the end of it and not erase what is already in that file ?

the first argument is the name of the file, and the second argument is a boolean value. if it is true and the file already exists, the contents of the file will not be erased and the new data will be appended to the end of the file. if the argument is false and the file already exists then it is assumed the existing file will be replaced

What is the syntax if a programmer did not want to use a sentinel value in a loop

this is accomplished through hasNextInt method. this can be used to check if another integer value exists in the file. If the method does not find another integer it returns false.


संबंधित स्टडी सेट्स

Chapter 12- The Digestive System

View Set

6.6.5 Test (CST): Complex Numbers Precalculus Sem 2

View Set

Chapter 11: Creativity, Innovation, and Leadership

View Set

Citizenship, Voting and Amendments

View Set