
Database System Concepts
7th Edition
ISBN: 9780078022159
Author: Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher: McGraw-Hill Education
expand_more
expand_more
format_list_bulleted
Question
Assume the file
data.dat
contains a sequence of binary data. Write a program that creates another file named
reverse.dat
that is a reverse copy of
data.dat
.
For example, the first byte of
reverse.dat
should be the same as the last byte of
data.dat
. The second byte of
reverse.dat
should be the same as the next-to-last byte of
data.dat
. And so on.
Handle exceptions in the following manner:
-
If aFileNotFoundExceptionis thrown, the program should display the string "File Error".
-
If any other exception is thrown, the program should display the string "Error".
The program should not display any screen output unless an exception is thrown as described above.
The name of your program class must be
ReverseFile
.
![M Inbox (22) ×
← → C
New Tab M
X
HH
Institution X
Gmail
Final Proje X ? Student Da x
☐ revel-ise.pearson.com/courses/63091c45093a8566d41c45cd/pages/urn:pearson:entity:01191e98-8075-4552-96f4-1542c9b80729?source=contents
Estudia fichas para l...
0816ExamGEOans.p... ▸ YouTube
Type here to search
</>
</>
X P Chapter 11 x ℗ Chapter 11 x ℗ Chapter 15 x C Please foll X
O
Maps
8:
GregEn directo OFichas de aprendiza...
0 of 5 points
Chapter 11: Programming Project 2
Unlimited tries
Question 1 of 1
2- {
3
4-
5
6
7
9
10
The program should not display any screen output unless an exception is
thrown as described above.
The name of your program class must be ReverseFile.
1 public class Reverse File
Assume the file data.dat contains a sequence of binary data. Write a
program that creates another file named reverse.dat that is a reverse
copy of data.dat.
For example, the first byte of reverse.dat should be the same as the last
byte of data.dat. The second byte of reverse.dat should be the same
as the next-to-last byte of data.dat. And so on.
Handle exceptions in the following manner:
• If a FileNotFoundException is thrown, the program should display
the string "File Error".
• If any other exception is thrown, the program should display the string
"Error".
Class diag X G The last pa × b Answered: X
Fichas de aprendiza...
public static void main(String[] args)
{
int number;
String str = "reverse.dat";
try
{
number = Integer.parseInt(str);
amazon
3
Fichas de aprendiza...
+
Fichas de aprendiza...
80°F Sunny
<
☆
Free Computers Fla...
4)
■
0
2:09 PM
12/6/2022
X
:
LJ](https://content.bartleby.com/qna-images/question/98e670cd-4d6d-4683-a173-616a918751aa/f95c0144-8177-43a8-b1d5-e7b766669911/l3rrw29_thumbnail.png)
Transcribed Image Text:M Inbox (22) ×
← → C
New Tab M
X
HH
Institution X
Gmail
Final Proje X ? Student Da x
☐ revel-ise.pearson.com/courses/63091c45093a8566d41c45cd/pages/urn:pearson:entity:01191e98-8075-4552-96f4-1542c9b80729?source=contents
Estudia fichas para l...
0816ExamGEOans.p... ▸ YouTube
Type here to search
</>
</>
X P Chapter 11 x ℗ Chapter 11 x ℗ Chapter 15 x C Please foll X
O
Maps
8:
GregEn directo OFichas de aprendiza...
0 of 5 points
Chapter 11: Programming Project 2
Unlimited tries
Question 1 of 1
2- {
3
4-
5
6
7
9
10
The program should not display any screen output unless an exception is
thrown as described above.
The name of your program class must be ReverseFile.
1 public class Reverse File
Assume the file data.dat contains a sequence of binary data. Write a
program that creates another file named reverse.dat that is a reverse
copy of data.dat.
For example, the first byte of reverse.dat should be the same as the last
byte of data.dat. The second byte of reverse.dat should be the same
as the next-to-last byte of data.dat. And so on.
Handle exceptions in the following manner:
• If a FileNotFoundException is thrown, the program should display
the string "File Error".
• If any other exception is thrown, the program should display the string
"Error".
Class diag X G The last pa × b Answered: X
Fichas de aprendiza...
public static void main(String[] args)
{
int number;
String str = "reverse.dat";
try
{
number = Integer.parseInt(str);
amazon
3
Fichas de aprendiza...
+
Fichas de aprendiza...
80°F Sunny
<
☆
Free Computers Fla...
4)
■
0
2:09 PM
12/6/2022
X
:
LJ
Expert Solution

This question has been solved!
Explore an expertly crafted, step-by-step solution for a thorough understanding of key concepts.
This is a popular solution
Trending nowThis is a popular solution!
Step by stepSolved in 2 steps

Knowledge Booster
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.Similar questions
- Finally, in a try/except statement, the finally suite runs only if the try suite's statements do not throw any exceptions.True or False?arrow_forwardConsider the following code snippet: pit_t pipefd[2]; pipe (pipefd); Which file descriptor represents the write end of the pipe? 1 pipefd[0] O pipefd[1] O The write end of the pipe cannot be determined at this pointarrow_forward4. Read from File Create a program that reads the values in the temperature data file created in the previous program. The program will display each temperature value in the file and calculate and display the average temperature. Be sure your program handles exceptions.arrow_forward
- Assume that there is a data file named as “data.txt”. This data file contains integer values in multiple lines, as shown below. You are asked to write statements in the main() method to open the file, read and print out the total of all the values (should be 55). Place your code into try-catch block so that the FileNotFoundException will be caught and an error message will be printed if no such file exists. data.txt 1 2 3 4 5 6 7 8 9 10 import java.util.*; import java.io.*; public class ReadAndPrint { pubilc static void main() { // your code goes here }arrow_forward4043143640684x3y7 In the code below, we compute the sum of integers in a file by reading them one line at a time. Rearrange the following lines of code so that the input file is closed even if the int function raises an exception. Follow Programming Tip "Do not use except and finally in the same try statement" in the Exception Handling section by placing the try block and finally clause inside the outer try block. How to use this tool Unused try : Check You've added 7 blocks, but 8 were expected. Not all tests passed. 1: Compare output Input Your output X 2: Compare output Input Output differs. See highlights below. Special character legend Your output numbers1.txt Expected output Total: 100 Closing file numbers2.txt Tester.py total = 0 infile open (input()) try: Total: 554 Closing file Error: Not an integer value. except ValueError : Error: Not an integer value. Total: 554 Closing file for line in infile : value = int(line) total= total + value finally : print("Error: Not an integer…arrow_forwardWrite one line of code that reads a full line from a file with file handle fp into a string defined aschar line[256]. Do this using both fscanf and fgets.arrow_forward
- Write a Java program to perform the following tasks:The program should ask the user for the name of an input file (scores.txt). Theinput file should contain 10 records. Each record in the input file shouldconsist of a name and score between 0 and 100 (inclusive). Eg: fred 95The program should open the input file as a text file (if the input file does notexist it should throw an exception) and read the contents line by line.Store each record in an array of a user-defined Score class. The Score classcan be kept very simple with 2 instance variables, a default constructor, getand set methods for the instance variables.Now process the array of Score class objects to determine:• The average of all scores• The largest score• The smallest scorearrow_forwardWrite a series of statements that produces a file with the name supplied by fileName and a single line stating "This Is File:" followed by the file's name. Check that the file's buffer has been emptied and that any system resources used by these statements have been freed. (Assume any exceptions are handled elsewhere.)arrow_forwardGiven an initialised variable fileName, write a sequence of statements that creates a file with the name specified by fileName and a single line containing "This Is File: " followed by the file's name. Verify that the data written to the file has been purged from its buffer and that all system resources consumed by these statements have been released. (Do not worry about any potential exceptions here; assume that they are handled elsewhere.)arrow_forward
- Focus on Basic file operations, exception handlingSave a copy of the file module6data.txt (attached to the assignment)Write a program in python that will a. Open the file module6data.txtb. Create a second file named processed.txtc. Read the numbers from the first file one at a time. For each number write into thesecond file, if possible, itsi. square ii. square root.iii. reciprocal (1/number) each on a separate line.• Use a math module function for the square root.• Use exception handling to trap possible errors. Error messages should be reported to the screen.d. Report the number of items in the original file and the number that were successfully stored in the second file.e. Report the number (count) of each type of error: ValueError, ZeroDivisionError, TypeErrorarrow_forwardHello, I am struggling to write a program in Python for a following problem: Write a file ( .py). In that file create a function that strips the first letters from all file names in a directory. If the new name is a duplicate of an existing name, Python will throw an exception. Handle that exception by adding “dup” a number as part of the files new name. Call that function from a Jupyter Notebook, passing in the number of characters to delete and the file path. Thank you!arrow_forward
arrow_back_ios
arrow_forward_ios
Recommended textbooks for you
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education

Database System Concepts
Computer Science
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:McGraw-Hill Education

Starting Out with Python (4th Edition)
Computer Science
ISBN:9780134444321
Author:Tony Gaddis
Publisher:PEARSON

Digital Fundamentals (11th Edition)
Computer Science
ISBN:9780132737968
Author:Thomas L. Floyd
Publisher:PEARSON

C How to Program (8th Edition)
Computer Science
ISBN:9780133976892
Author:Paul J. Deitel, Harvey Deitel
Publisher:PEARSON

Database Systems: Design, Implementation, & Manag...
Computer Science
ISBN:9781337627900
Author:Carlos Coronel, Steven Morris
Publisher:Cengage Learning

Programmable Logic Controllers
Computer Science
ISBN:9780073373843
Author:Frank D. Petruzella
Publisher:McGraw-Hill Education