Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

The code provided below contains syntax and / or logic errors. In each case, determine and fix the problem, remove all syntax and coding errors,

The code provided below contains syntax and/or logic errors. In each case, determine and fix the problem, remove all syntax and coding errors, and run the program to ensure it works properly.
Code:
// Program reads in a file of phone numbers without area codes
// inserts "(312)" in front of each phone number
// and produces an output file with the new complete phone numbers
import java.nio.file.*;
import java.io.*;
import java.nio.channels.FileChannel;
import static java.nio.file.StandardOpenOption.*;
public class DebuggingExercise05{
public static void main(String[] args)
{
Path fileIn =
Paths.get("/root/sandbox/DebugData2.txt");
Path fileOut =
Paths.get("/root/sandbox/DebugData2New.txt");
String areaCode ="(312)";
String phone;
InputStream input = nul;
OutputStream output = nul;
try
{
input = Files.newInputStream(fileIn);
BufferedReader reader = BufferedReader
(new InputStreamReader(input));
output = Files.newOutputStream(fileOut);
phone = reader.readLine();
while(phone = null)
{
phone = areaCode + phone + System.getProperty("line.separator");
byte phoneBytes = phone.getBytes();
output.write(phoneBytes);
phone = reader.readline();
}
input.closes();
output.closes();
}
catch (IOException e)
{
System.out.println(e);
}
}
}

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

T Sql Window Functions For Data Analysis And Beyond

Authors: Itzik Ben Gan

2nd Edition

0135861446, 978-0135861448

More Books

Students also viewed these Databases questions

Question

= 4. What are the characteristics of a good team mission statement?

Answered: 1 week ago

Question

Having redundant data is a desirable practice in database design.

Answered: 1 week ago