SlideShare a Scribd company logo
1 of 3
Download to read offline
I need help with this Java assignment. Please include comments throughout. Thanks
Write a program that will make a copy of a text file, line by line. Read the name of the existing
file and the name of the new file - the copy - from the keyboard. Use the methods of the class
File to test whether the original file exists and can be read. If not, display an error message and
abort the program. Similarly, see whether the name of the new file already exists. If so, display a
warning message and allow the user to either abort the program , overwrite the existing file, or
enter a new name for the file.
Solution
import java.util.Scanner;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.PrintWriter;
public class Project4
{
public static void main(String[] args)
{
System.out.print("Enter file name: ");
Scanner keybaord = new Scanner(System.in);
String fileName = keyboard.next();
Scanner inputStream = null;
System.out.println(fileName);
File fileObject = new File("old.txt");
String path = "C:LibraryDocumentsNetBeansProjectsProject4";
File source = new File(path);
try
{
inputStream = new Scanner(new File(fileName));
}
catch(FileNotFoundException e)
{
System.out.println("Error opening the file " + fileName);
System.exit(0);
}
while (inputStream.hasNextLine())
{
String line = inputStream.nextLine();
System.out.println(line);
}
inputStream.close();
boolean fileOK = false;
while (!fileOK)
{
if (!fileObject.exists())
System.out.println("No such file");
else if (!fileObject.canRead())
System.out.println("That file is not readable.");
else
fileOK = true;
if (!fileOK)
{
System.out.println("Enter the file name again:");
fileName = keyboard.next();
fileObject = new File(fileName);
}
}
}
public static void PrintWriter openOutputTextFile
{
(String fileName) throws FileNotFoundException
{
PrintWriter toFile = new PrintWriter(fileName);
return toFile;
}
PrintWriter outputStream = null;
try
{
outputStream = openOutputTextFile("old.txt");
}
catch (FileNotFoundException e)
}
}

More Related Content

Similar to I need help with this Java assignment. Please include comments throu.pdf

Write a java program that allows the user to input the name of a file.docx
Write a java program that allows the user to input  the name of a file.docxWrite a java program that allows the user to input  the name of a file.docx
Write a java program that allows the user to input the name of a file.docxnoreendchesterton753
 
Change the code in Writer.java only to get it working. Must contain .pdf
Change the code in Writer.java only to get it working. Must contain .pdfChange the code in Writer.java only to get it working. Must contain .pdf
Change the code in Writer.java only to get it working. Must contain .pdfsecunderbadtirumalgi
 
File Handling in Java.pdf
File Handling in Java.pdfFile Handling in Java.pdf
File Handling in Java.pdfSudhanshiBakre1
 
In JavaWrite a program that reads a file and counts how many line.pdf
In JavaWrite a program that reads a file and counts how many line.pdfIn JavaWrite a program that reads a file and counts how many line.pdf
In JavaWrite a program that reads a file and counts how many line.pdfsuresh640714
 
Write a program in java that asks a user for a file name and prints .pdf
Write a program in java that asks a user for a file name and prints .pdfWrite a program in java that asks a user for a file name and prints .pdf
Write a program in java that asks a user for a file name and prints .pdfatulkapoor33
 
Java Program using RecursionWrite a program that reads in a file .pdf
Java Program using RecursionWrite a program that reads in a file .pdfJava Program using RecursionWrite a program that reads in a file .pdf
Java Program using RecursionWrite a program that reads in a file .pdfduttakajal70
 
Write a program CountWords in Java that reads text from a file and b.pdf
Write a program CountWords in Java that reads text from a file and b.pdfWrite a program CountWords in Java that reads text from a file and b.pdf
Write a program CountWords in Java that reads text from a file and b.pdfrushabhshah600
 
The Java Program for the above given isimport java.io.File;impo.pdf
The Java Program for the above given isimport java.io.File;impo.pdfThe Java Program for the above given isimport java.io.File;impo.pdf
The Java Program for the above given isimport java.io.File;impo.pdfanjanacottonmills
 
File- LineScrabbleDriver-java -U 4- in-Desktop-Guess this is the death.docx
File- LineScrabbleDriver-java -U 4- in-Desktop-Guess this is the death.docxFile- LineScrabbleDriver-java -U 4- in-Desktop-Guess this is the death.docx
File- LineScrabbleDriver-java -U 4- in-Desktop-Guess this is the death.docxjkristen1
 
Input output files in java
Input output files in javaInput output files in java
Input output files in javaKavitha713564
 
Common Programming Errors by Beginners in Java
Common Programming Errors by Beginners in JavaCommon Programming Errors by Beginners in Java
Common Programming Errors by Beginners in JavaRavi_Kant_Sahu
 
Basics of java 2
Basics of java 2Basics of java 2
Basics of java 2Raghu nath
 
Write a program that asks the user for the name of a file. The progr.pdf
Write a program that asks the user for the name of a file. The progr.pdfWrite a program that asks the user for the name of a file. The progr.pdf
Write a program that asks the user for the name of a file. The progr.pdfarri2009av
 
I would like this to be answered in java 9-8 LAB- Parsing food data.pdf
I would like this to be answered in java   9-8 LAB- Parsing food data.pdfI would like this to be answered in java   9-8 LAB- Parsing food data.pdf
I would like this to be answered in java 9-8 LAB- Parsing food data.pdfsojandas029
 
Description 1) Create a Lab2 folder for this project2.docx
Description       1)  Create a Lab2 folder for this project2.docxDescription       1)  Create a Lab2 folder for this project2.docx
Description 1) Create a Lab2 folder for this project2.docxtheodorelove43763
 
Parsing food data lab - Please answer in JAVA Given a text file contai.pdf
Parsing food data lab - Please answer in JAVA Given a text file contai.pdfParsing food data lab - Please answer in JAVA Given a text file contai.pdf
Parsing food data lab - Please answer in JAVA Given a text file contai.pdfarcellzone
 
Write a java program that would ask the user to enter an input file .pdf
Write a java program that would ask the user to enter an input file .pdfWrite a java program that would ask the user to enter an input file .pdf
Write a java program that would ask the user to enter an input file .pdfudit652068
 

Similar to I need help with this Java assignment. Please include comments throu.pdf (20)

Write a java program that allows the user to input the name of a file.docx
Write a java program that allows the user to input  the name of a file.docxWrite a java program that allows the user to input  the name of a file.docx
Write a java program that allows the user to input the name of a file.docx
 
FileHandling.docx
FileHandling.docxFileHandling.docx
FileHandling.docx
 
Change the code in Writer.java only to get it working. Must contain .pdf
Change the code in Writer.java only to get it working. Must contain .pdfChange the code in Writer.java only to get it working. Must contain .pdf
Change the code in Writer.java only to get it working. Must contain .pdf
 
ExtraFileIO.pptx
ExtraFileIO.pptxExtraFileIO.pptx
ExtraFileIO.pptx
 
File Handling in Java.pdf
File Handling in Java.pdfFile Handling in Java.pdf
File Handling in Java.pdf
 
In JavaWrite a program that reads a file and counts how many line.pdf
In JavaWrite a program that reads a file and counts how many line.pdfIn JavaWrite a program that reads a file and counts how many line.pdf
In JavaWrite a program that reads a file and counts how many line.pdf
 
Write a program in java that asks a user for a file name and prints .pdf
Write a program in java that asks a user for a file name and prints .pdfWrite a program in java that asks a user for a file name and prints .pdf
Write a program in java that asks a user for a file name and prints .pdf
 
Java Program using RecursionWrite a program that reads in a file .pdf
Java Program using RecursionWrite a program that reads in a file .pdfJava Program using RecursionWrite a program that reads in a file .pdf
Java Program using RecursionWrite a program that reads in a file .pdf
 
Write a program CountWords in Java that reads text from a file and b.pdf
Write a program CountWords in Java that reads text from a file and b.pdfWrite a program CountWords in Java that reads text from a file and b.pdf
Write a program CountWords in Java that reads text from a file and b.pdf
 
The Java Program for the above given isimport java.io.File;impo.pdf
The Java Program for the above given isimport java.io.File;impo.pdfThe Java Program for the above given isimport java.io.File;impo.pdf
The Java Program for the above given isimport java.io.File;impo.pdf
 
File- LineScrabbleDriver-java -U 4- in-Desktop-Guess this is the death.docx
File- LineScrabbleDriver-java -U 4- in-Desktop-Guess this is the death.docxFile- LineScrabbleDriver-java -U 4- in-Desktop-Guess this is the death.docx
File- LineScrabbleDriver-java -U 4- in-Desktop-Guess this is the death.docx
 
Input output files in java
Input output files in javaInput output files in java
Input output files in java
 
Basic input-output-v.1.1
Basic input-output-v.1.1Basic input-output-v.1.1
Basic input-output-v.1.1
 
Common Programming Errors by Beginners in Java
Common Programming Errors by Beginners in JavaCommon Programming Errors by Beginners in Java
Common Programming Errors by Beginners in Java
 
Basics of java 2
Basics of java 2Basics of java 2
Basics of java 2
 
Write a program that asks the user for the name of a file. The progr.pdf
Write a program that asks the user for the name of a file. The progr.pdfWrite a program that asks the user for the name of a file. The progr.pdf
Write a program that asks the user for the name of a file. The progr.pdf
 
I would like this to be answered in java 9-8 LAB- Parsing food data.pdf
I would like this to be answered in java   9-8 LAB- Parsing food data.pdfI would like this to be answered in java   9-8 LAB- Parsing food data.pdf
I would like this to be answered in java 9-8 LAB- Parsing food data.pdf
 
Description 1) Create a Lab2 folder for this project2.docx
Description       1)  Create a Lab2 folder for this project2.docxDescription       1)  Create a Lab2 folder for this project2.docx
Description 1) Create a Lab2 folder for this project2.docx
 
Parsing food data lab - Please answer in JAVA Given a text file contai.pdf
Parsing food data lab - Please answer in JAVA Given a text file contai.pdfParsing food data lab - Please answer in JAVA Given a text file contai.pdf
Parsing food data lab - Please answer in JAVA Given a text file contai.pdf
 
Write a java program that would ask the user to enter an input file .pdf
Write a java program that would ask the user to enter an input file .pdfWrite a java program that would ask the user to enter an input file .pdf
Write a java program that would ask the user to enter an input file .pdf
 

More from sales98

Genetic evidence supports which of the following explanations for the.pdf
Genetic evidence supports which of the following explanations for the.pdfGenetic evidence supports which of the following explanations for the.pdf
Genetic evidence supports which of the following explanations for the.pdfsales98
 
Complete the following table for InvestmentsFair value method(s).pdf
Complete the following table for InvestmentsFair value method(s).pdfComplete the following table for InvestmentsFair value method(s).pdf
Complete the following table for InvestmentsFair value method(s).pdfsales98
 
Find the values of the trigonometric functions of from the informat.pdf
Find the values of the trigonometric functions of  from the informat.pdfFind the values of the trigonometric functions of  from the informat.pdf
Find the values of the trigonometric functions of from the informat.pdfsales98
 
Evolution is driven by environmental that put selection pressure on o.pdf
Evolution is driven by environmental that put selection pressure on o.pdfEvolution is driven by environmental that put selection pressure on o.pdf
Evolution is driven by environmental that put selection pressure on o.pdfsales98
 
e) As a practical matter, trade-offs of qualitative characteristics o.pdf
e) As a practical matter, trade-offs of qualitative characteristics o.pdfe) As a practical matter, trade-offs of qualitative characteristics o.pdf
e) As a practical matter, trade-offs of qualitative characteristics o.pdfsales98
 
Determine whether the relation defines y as a function of x. Give the.pdf
Determine whether the relation defines y as a function of x. Give the.pdfDetermine whether the relation defines y as a function of x. Give the.pdf
Determine whether the relation defines y as a function of x. Give the.pdfsales98
 
Connor and his wife are guests at the hotel, having reserved a room .pdf
Connor and his wife are guests at the hotel, having reserved a room .pdfConnor and his wife are guests at the hotel, having reserved a room .pdf
Connor and his wife are guests at the hotel, having reserved a room .pdfsales98
 
Define the role of the entrepreneur in the U.S. economy and describe.pdf
Define the role of the entrepreneur in the U.S. economy and describe.pdfDefine the role of the entrepreneur in the U.S. economy and describe.pdf
Define the role of the entrepreneur in the U.S. economy and describe.pdfsales98
 
Consider a double-linked linked list implementation with the followin.pdf
Consider a double-linked linked list implementation with the followin.pdfConsider a double-linked linked list implementation with the followin.pdf
Consider a double-linked linked list implementation with the followin.pdfsales98
 
8. You may have heard that drinking soda or acid is bad for your teet.pdf
8. You may have heard that drinking soda or acid is bad for your teet.pdf8. You may have heard that drinking soda or acid is bad for your teet.pdf
8. You may have heard that drinking soda or acid is bad for your teet.pdfsales98
 
alter ego theory. TRUE FALSE Multiple Choice her nephew Dru to manag.pdf
alter ego theory. TRUE FALSE Multiple Choice her nephew Dru to manag.pdfalter ego theory. TRUE FALSE Multiple Choice her nephew Dru to manag.pdf
alter ego theory. TRUE FALSE Multiple Choice her nephew Dru to manag.pdfsales98
 
2)Are enterprise information portals making executive information sy.pdf
2)Are enterprise information portals making executive information sy.pdf2)Are enterprise information portals making executive information sy.pdf
2)Are enterprise information portals making executive information sy.pdfsales98
 
5. How the tax system changes the distribution of income among capita.pdf
5. How the tax system changes the distribution of income among capita.pdf5. How the tax system changes the distribution of income among capita.pdf
5. How the tax system changes the distribution of income among capita.pdfsales98
 
Write Java FX code for this pseudocode of the void initilizaHistoryL.pdf
Write Java FX code for this pseudocode of the void initilizaHistoryL.pdfWrite Java FX code for this pseudocode of the void initilizaHistoryL.pdf
Write Java FX code for this pseudocode of the void initilizaHistoryL.pdfsales98
 
Your name Date Explanation of Program -Modifying the first .pdf
Your name Date  Explanation of Program -Modifying the first .pdfYour name Date  Explanation of Program -Modifying the first .pdf
Your name Date Explanation of Program -Modifying the first .pdfsales98
 
Why is it that ozone is not desirable at the surface of earth, but i.pdf
Why is it that ozone is not desirable at the surface of earth, but i.pdfWhy is it that ozone is not desirable at the surface of earth, but i.pdf
Why is it that ozone is not desirable at the surface of earth, but i.pdfsales98
 
Write a program that moves the ball in a pane. You should define a p.pdf
Write a program that moves the ball in a pane. You should define a p.pdfWrite a program that moves the ball in a pane. You should define a p.pdf
Write a program that moves the ball in a pane. You should define a p.pdfsales98
 
Which ape has been known to make territory patrols and wage war o.pdf
Which ape has been known to make territory patrols and wage war o.pdfWhich ape has been known to make territory patrols and wage war o.pdf
Which ape has been known to make territory patrols and wage war o.pdfsales98
 
What are the limitations of an expert systemSolutionLIMITATIO.pdf
What are the limitations of an expert systemSolutionLIMITATIO.pdfWhat are the limitations of an expert systemSolutionLIMITATIO.pdf
What are the limitations of an expert systemSolutionLIMITATIO.pdfsales98
 
Using the scenario provided in the Milestone One Guidelines and Rubr.pdf
Using the scenario provided in the Milestone One Guidelines and Rubr.pdfUsing the scenario provided in the Milestone One Guidelines and Rubr.pdf
Using the scenario provided in the Milestone One Guidelines and Rubr.pdfsales98
 

More from sales98 (20)

Genetic evidence supports which of the following explanations for the.pdf
Genetic evidence supports which of the following explanations for the.pdfGenetic evidence supports which of the following explanations for the.pdf
Genetic evidence supports which of the following explanations for the.pdf
 
Complete the following table for InvestmentsFair value method(s).pdf
Complete the following table for InvestmentsFair value method(s).pdfComplete the following table for InvestmentsFair value method(s).pdf
Complete the following table for InvestmentsFair value method(s).pdf
 
Find the values of the trigonometric functions of from the informat.pdf
Find the values of the trigonometric functions of  from the informat.pdfFind the values of the trigonometric functions of  from the informat.pdf
Find the values of the trigonometric functions of from the informat.pdf
 
Evolution is driven by environmental that put selection pressure on o.pdf
Evolution is driven by environmental that put selection pressure on o.pdfEvolution is driven by environmental that put selection pressure on o.pdf
Evolution is driven by environmental that put selection pressure on o.pdf
 
e) As a practical matter, trade-offs of qualitative characteristics o.pdf
e) As a practical matter, trade-offs of qualitative characteristics o.pdfe) As a practical matter, trade-offs of qualitative characteristics o.pdf
e) As a practical matter, trade-offs of qualitative characteristics o.pdf
 
Determine whether the relation defines y as a function of x. Give the.pdf
Determine whether the relation defines y as a function of x. Give the.pdfDetermine whether the relation defines y as a function of x. Give the.pdf
Determine whether the relation defines y as a function of x. Give the.pdf
 
Connor and his wife are guests at the hotel, having reserved a room .pdf
Connor and his wife are guests at the hotel, having reserved a room .pdfConnor and his wife are guests at the hotel, having reserved a room .pdf
Connor and his wife are guests at the hotel, having reserved a room .pdf
 
Define the role of the entrepreneur in the U.S. economy and describe.pdf
Define the role of the entrepreneur in the U.S. economy and describe.pdfDefine the role of the entrepreneur in the U.S. economy and describe.pdf
Define the role of the entrepreneur in the U.S. economy and describe.pdf
 
Consider a double-linked linked list implementation with the followin.pdf
Consider a double-linked linked list implementation with the followin.pdfConsider a double-linked linked list implementation with the followin.pdf
Consider a double-linked linked list implementation with the followin.pdf
 
8. You may have heard that drinking soda or acid is bad for your teet.pdf
8. You may have heard that drinking soda or acid is bad for your teet.pdf8. You may have heard that drinking soda or acid is bad for your teet.pdf
8. You may have heard that drinking soda or acid is bad for your teet.pdf
 
alter ego theory. TRUE FALSE Multiple Choice her nephew Dru to manag.pdf
alter ego theory. TRUE FALSE Multiple Choice her nephew Dru to manag.pdfalter ego theory. TRUE FALSE Multiple Choice her nephew Dru to manag.pdf
alter ego theory. TRUE FALSE Multiple Choice her nephew Dru to manag.pdf
 
2)Are enterprise information portals making executive information sy.pdf
2)Are enterprise information portals making executive information sy.pdf2)Are enterprise information portals making executive information sy.pdf
2)Are enterprise information portals making executive information sy.pdf
 
5. How the tax system changes the distribution of income among capita.pdf
5. How the tax system changes the distribution of income among capita.pdf5. How the tax system changes the distribution of income among capita.pdf
5. How the tax system changes the distribution of income among capita.pdf
 
Write Java FX code for this pseudocode of the void initilizaHistoryL.pdf
Write Java FX code for this pseudocode of the void initilizaHistoryL.pdfWrite Java FX code for this pseudocode of the void initilizaHistoryL.pdf
Write Java FX code for this pseudocode of the void initilizaHistoryL.pdf
 
Your name Date Explanation of Program -Modifying the first .pdf
Your name Date  Explanation of Program -Modifying the first .pdfYour name Date  Explanation of Program -Modifying the first .pdf
Your name Date Explanation of Program -Modifying the first .pdf
 
Why is it that ozone is not desirable at the surface of earth, but i.pdf
Why is it that ozone is not desirable at the surface of earth, but i.pdfWhy is it that ozone is not desirable at the surface of earth, but i.pdf
Why is it that ozone is not desirable at the surface of earth, but i.pdf
 
Write a program that moves the ball in a pane. You should define a p.pdf
Write a program that moves the ball in a pane. You should define a p.pdfWrite a program that moves the ball in a pane. You should define a p.pdf
Write a program that moves the ball in a pane. You should define a p.pdf
 
Which ape has been known to make territory patrols and wage war o.pdf
Which ape has been known to make territory patrols and wage war o.pdfWhich ape has been known to make territory patrols and wage war o.pdf
Which ape has been known to make territory patrols and wage war o.pdf
 
What are the limitations of an expert systemSolutionLIMITATIO.pdf
What are the limitations of an expert systemSolutionLIMITATIO.pdfWhat are the limitations of an expert systemSolutionLIMITATIO.pdf
What are the limitations of an expert systemSolutionLIMITATIO.pdf
 
Using the scenario provided in the Milestone One Guidelines and Rubr.pdf
Using the scenario provided in the Milestone One Guidelines and Rubr.pdfUsing the scenario provided in the Milestone One Guidelines and Rubr.pdf
Using the scenario provided in the Milestone One Guidelines and Rubr.pdf
 

Recently uploaded

Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Krashi Coaching
 
Mastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionMastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionSafetyChain Software
 
APM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAPM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAssociation for Project Management
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfsanyamsingh5019
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxGaneshChakor2
 
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Celine George
 
Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxpboyjonauth
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformChameera Dedduwage
 
URLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website AppURLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website AppCeline George
 
How to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxHow to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxmanuelaromero2013
 
Science 7 - LAND and SEA BREEZE and its Characteristics
Science 7 - LAND and SEA BREEZE and its CharacteristicsScience 7 - LAND and SEA BREEZE and its Characteristics
Science 7 - LAND and SEA BREEZE and its CharacteristicsKarinaGenton
 
Separation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesSeparation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesFatimaKhan178732
 
Crayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon ACrayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon AUnboundStockton
 
Presiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsPresiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsanshu789521
 
Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeThiyagu K
 
MENTAL STATUS EXAMINATION format.docx
MENTAL     STATUS EXAMINATION format.docxMENTAL     STATUS EXAMINATION format.docx
MENTAL STATUS EXAMINATION format.docxPoojaSen20
 
Concept of Vouching. B.Com(Hons) /B.Compdf
Concept of Vouching. B.Com(Hons) /B.CompdfConcept of Vouching. B.Com(Hons) /B.Compdf
Concept of Vouching. B.Com(Hons) /B.CompdfUmakantAnnand
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingTechSoup
 
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991RKavithamani
 

Recently uploaded (20)

Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
 
Mastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionMastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory Inspection
 
APM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAPM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across Sectors
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdf
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptx
 
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
 
Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptx
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy Reform
 
URLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website AppURLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website App
 
How to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxHow to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptx
 
Science 7 - LAND and SEA BREEZE and its Characteristics
Science 7 - LAND and SEA BREEZE and its CharacteristicsScience 7 - LAND and SEA BREEZE and its Characteristics
Science 7 - LAND and SEA BREEZE and its Characteristics
 
Separation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesSeparation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and Actinides
 
Crayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon ACrayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon A
 
Presiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsPresiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha elections
 
Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and Mode
 
MENTAL STATUS EXAMINATION format.docx
MENTAL     STATUS EXAMINATION format.docxMENTAL     STATUS EXAMINATION format.docx
MENTAL STATUS EXAMINATION format.docx
 
Concept of Vouching. B.Com(Hons) /B.Compdf
Concept of Vouching. B.Com(Hons) /B.CompdfConcept of Vouching. B.Com(Hons) /B.Compdf
Concept of Vouching. B.Com(Hons) /B.Compdf
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy Consulting
 
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991
 

I need help with this Java assignment. Please include comments throu.pdf

  • 1. I need help with this Java assignment. Please include comments throughout. Thanks Write a program that will make a copy of a text file, line by line. Read the name of the existing file and the name of the new file - the copy - from the keyboard. Use the methods of the class File to test whether the original file exists and can be read. If not, display an error message and abort the program. Similarly, see whether the name of the new file already exists. If so, display a warning message and allow the user to either abort the program , overwrite the existing file, or enter a new name for the file. Solution import java.util.Scanner; import java.io.File; import java.io.FileNotFoundException; import java.io.PrintWriter; public class Project4 { public static void main(String[] args) { System.out.print("Enter file name: "); Scanner keybaord = new Scanner(System.in); String fileName = keyboard.next(); Scanner inputStream = null; System.out.println(fileName); File fileObject = new File("old.txt"); String path = "C:LibraryDocumentsNetBeansProjectsProject4"; File source = new File(path); try { inputStream = new Scanner(new File(fileName)); } catch(FileNotFoundException e) { System.out.println("Error opening the file " + fileName); System.exit(0); }
  • 2. while (inputStream.hasNextLine()) { String line = inputStream.nextLine(); System.out.println(line); } inputStream.close(); boolean fileOK = false; while (!fileOK) { if (!fileObject.exists()) System.out.println("No such file"); else if (!fileObject.canRead()) System.out.println("That file is not readable."); else fileOK = true; if (!fileOK) { System.out.println("Enter the file name again:"); fileName = keyboard.next(); fileObject = new File(fileName); } } } public static void PrintWriter openOutputTextFile { (String fileName) throws FileNotFoundException { PrintWriter toFile = new PrintWriter(fileName); return toFile; } PrintWriter outputStream = null; try { outputStream = openOutputTextFile("old.txt"); } catch (FileNotFoundException e)
  • 3. } }