SlideShare a Scribd company logo
1 of 3
Download to read offline
Write a java program that would ask the user to enter an input file name, and an output file name.
Then the program reads the content of the input file, and then writes the content of the input file
to the output file with each line proceeded with a line number followed by a colon. The line
numbering should start at 1.
should be used the following technique
(a) while loop should be used to complete the program.
(b)Scanner classisused
(c) PrintWriter class is used
(d) The files are closed before the program terminates.
ExampleOriginal Input fileOutput file with line number added1341: 1341252: 1251123:
1121894: 189
Solution
FileCopier.java:-
import java.io.File;
import java.io.FileInputStream;
import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.Scanner;
public class FileCopier {
public static void main(String[] args) throws IOException{
Scanner in=new Scanner(System.in);
System.out.println("Enter input file");
File inputFile=new File(in.nextLine());
if(!inputFile.exists()){
System.out.println("Source file doesn't exist");
System.exit(0);
}
FileInputStream fis=new FileInputStream(inputFile);
System.out.println("Enter output file");
FileWriter fw=new FileWriter(in.nextLine());
PrintWriter pw=new PrintWriter(fw);
in=new Scanner(inputFile);
int i=1;
while(in.hasNextLine()){
String s=in.nextLine();
pw.write(i++ + ": " + s + " ");
}
pw.flush();pw.close();
}
}
Console output:
Enter input file
test.txt
Enter output file
output.txt
Sample run 1:-
test.txt:
hey
123
.
howdy
output.txt:
1: hey
2: 123
3: .
4: howdy
Sample run 2:-
test.txt:
123
345
567
789
output.txt
1: 123
2: 345
3: 567
4: 789

More Related Content

Similar to Write a java program that would ask the user to enter an input file .pdf

Java Hello program with output
Java Hello program with outputJava Hello program with output
Java Hello program with outputaashukaushik
 
Hi, I need help with a java programming project. specifically practi.pdf
Hi, I need help with a java programming project. specifically practi.pdfHi, I need help with a java programming project. specifically practi.pdf
Hi, I need help with a java programming project. specifically practi.pdfPRATIKSINHA7304
 
i am finishing a project for my cs 0401 java course. I have complete.pdf
i am finishing a project for my cs 0401 java course. I have complete.pdfi am finishing a project for my cs 0401 java course. I have complete.pdf
i am finishing a project for my cs 0401 java course. I have complete.pdfdeepaksatrker
 
Java Notes by C. Sreedhar, GPREC
Java Notes by C. Sreedhar, GPRECJava Notes by C. Sreedhar, GPREC
Java Notes by C. Sreedhar, GPRECSreedhar Chowdam
 
Chapter 2.1
Chapter 2.1Chapter 2.1
Chapter 2.1sotlsoc
 
Write a java program that allows the user to input the name of a fil.docx
 Write a java program that allows the user to input  the name of a fil.docx Write a java program that allows the user to input  the name of a fil.docx
Write a java program that allows the user to input the name of a fil.docxajoy21
 
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
 
File Handling in Java.pdf
File Handling in Java.pdfFile Handling in Java.pdf
File Handling in Java.pdfSudhanshiBakre1
 
Introduction to Software Development
Introduction to Software DevelopmentIntroduction to Software Development
Introduction to Software DevelopmentZeeshan MIrza
 
Java session08
Java session08Java session08
Java session08Niit Care
 
JAVA Q2- Write a program that reads strings from the user and writes t.docx
JAVA Q2- Write a program that reads strings from the user and writes t.docxJAVA Q2- Write a program that reads strings from the user and writes t.docx
JAVA Q2- Write a program that reads strings from the user and writes t.docxmichael1810
 
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
 
Core Java Programming Language (JSE) : Chapter XI - Console I/O and File I/O
Core Java Programming Language (JSE) : Chapter XI - Console I/O and File I/OCore Java Programming Language (JSE) : Chapter XI - Console I/O and File I/O
Core Java Programming Language (JSE) : Chapter XI - Console I/O and File I/OWebStackAcademy
 
Io files and web
Io files and webIo files and web
Io files and webAhmed Nobi
 
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
 
1.26 File Input-Output in JAVA.pptx
1.26 File Input-Output in JAVA.pptx1.26 File Input-Output in JAVA.pptx
1.26 File Input-Output in JAVA.pptxYashrajMohrir
 
j-chap1-Basics.ppt
j-chap1-Basics.pptj-chap1-Basics.ppt
j-chap1-Basics.pptSmitaBorkar9
 
Object oriented programming la bmanual jntu
Object oriented programming la bmanual jntuObject oriented programming la bmanual jntu
Object oriented programming la bmanual jntuKhurshid Asghar
 

Similar to Write a java program that would ask the user to enter an input file .pdf (20)

Java Hello program with output
Java Hello program with outputJava Hello program with output
Java Hello program with output
 
Hi, I need help with a java programming project. specifically practi.pdf
Hi, I need help with a java programming project. specifically practi.pdfHi, I need help with a java programming project. specifically practi.pdf
Hi, I need help with a java programming project. specifically practi.pdf
 
Getting Program Input
Getting Program Input Getting Program Input
Getting Program Input
 
i am finishing a project for my cs 0401 java course. I have complete.pdf
i am finishing a project for my cs 0401 java course. I have complete.pdfi am finishing a project for my cs 0401 java course. I have complete.pdf
i am finishing a project for my cs 0401 java course. I have complete.pdf
 
Java Notes
Java Notes Java Notes
Java Notes
 
Java Notes by C. Sreedhar, GPREC
Java Notes by C. Sreedhar, GPRECJava Notes by C. Sreedhar, GPREC
Java Notes by C. Sreedhar, GPREC
 
Chapter 2.1
Chapter 2.1Chapter 2.1
Chapter 2.1
 
Write a java program that allows the user to input the name of a fil.docx
 Write a java program that allows the user to input  the name of a fil.docx Write a java program that allows the user to input  the name of a fil.docx
Write a java program that allows the user to input the name of a fil.docx
 
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
 
File Handling in Java.pdf
File Handling in Java.pdfFile Handling in Java.pdf
File Handling in Java.pdf
 
Introduction to Software Development
Introduction to Software DevelopmentIntroduction to Software Development
Introduction to Software Development
 
Java session08
Java session08Java session08
Java session08
 
JAVA Q2- Write a program that reads strings from the user and writes t.docx
JAVA Q2- Write a program that reads strings from the user and writes t.docxJAVA Q2- Write a program that reads strings from the user and writes t.docx
JAVA Q2- Write a program that reads strings from the user and writes t.docx
 
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
 
Core Java Programming Language (JSE) : Chapter XI - Console I/O and File I/O
Core Java Programming Language (JSE) : Chapter XI - Console I/O and File I/OCore Java Programming Language (JSE) : Chapter XI - Console I/O and File I/O
Core Java Programming Language (JSE) : Chapter XI - Console I/O and File I/O
 
Io files and web
Io files and webIo files and web
Io files and web
 
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
 
1.26 File Input-Output in JAVA.pptx
1.26 File Input-Output in JAVA.pptx1.26 File Input-Output in JAVA.pptx
1.26 File Input-Output in JAVA.pptx
 
j-chap1-Basics.ppt
j-chap1-Basics.pptj-chap1-Basics.ppt
j-chap1-Basics.ppt
 
Object oriented programming la bmanual jntu
Object oriented programming la bmanual jntuObject oriented programming la bmanual jntu
Object oriented programming la bmanual jntu
 

More from udit652068

Discuss briefly and with examples, What key measures need to be take.pdf
Discuss briefly and with examples, What key measures need to be take.pdfDiscuss briefly and with examples, What key measures need to be take.pdf
Discuss briefly and with examples, What key measures need to be take.pdfudit652068
 
Did BP respond in a manner that was appropriate with the oil spill t.pdf
Did BP respond in a manner that was appropriate with the oil spill t.pdfDid BP respond in a manner that was appropriate with the oil spill t.pdf
Did BP respond in a manner that was appropriate with the oil spill t.pdfudit652068
 
Describe and provide at least two examples of direct transmission of.pdf
Describe and provide at least two examples of direct transmission of.pdfDescribe and provide at least two examples of direct transmission of.pdf
Describe and provide at least two examples of direct transmission of.pdfudit652068
 
Define VRIO in business strategy Define VRIO in business strat.pdf
Define VRIO in business strategy Define VRIO in business strat.pdfDefine VRIO in business strategy Define VRIO in business strat.pdf
Define VRIO in business strategy Define VRIO in business strat.pdfudit652068
 
Define e-commerce and describe how it differs from e-business.So.pdf
Define e-commerce and describe how it differs from e-business.So.pdfDefine e-commerce and describe how it differs from e-business.So.pdf
Define e-commerce and describe how it differs from e-business.So.pdfudit652068
 
Building Social Business - EssaySolutionBuilding social busine.pdf
Building Social Business - EssaySolutionBuilding social busine.pdfBuilding Social Business - EssaySolutionBuilding social busine.pdf
Building Social Business - EssaySolutionBuilding social busine.pdfudit652068
 
You are to write a C++ program to produce an inventory repor.pdf
You are to write a C++ program to produce an inventory repor.pdfYou are to write a C++ program to produce an inventory repor.pdf
You are to write a C++ program to produce an inventory repor.pdfudit652068
 
Working with Layout Managers. Notes 1. In part 2, note that the Gam.pdf
Working with Layout Managers. Notes 1. In part 2, note that the Gam.pdfWorking with Layout Managers. Notes 1. In part 2, note that the Gam.pdf
Working with Layout Managers. Notes 1. In part 2, note that the Gam.pdfudit652068
 
Which of the following defines a method doubleEach that returns an ar.pdf
Which of the following defines a method doubleEach that returns an ar.pdfWhich of the following defines a method doubleEach that returns an ar.pdf
Which of the following defines a method doubleEach that returns an ar.pdfudit652068
 
When the Fed provides more reserves toprovides more reserves to.pdf
When the Fed provides more reserves toprovides more reserves to.pdfWhen the Fed provides more reserves toprovides more reserves to.pdf
When the Fed provides more reserves toprovides more reserves to.pdfudit652068
 
What is a common infrastructure and what does it provideSolutio.pdf
What is a common infrastructure and what does it provideSolutio.pdfWhat is a common infrastructure and what does it provideSolutio.pdf
What is a common infrastructure and what does it provideSolutio.pdfudit652068
 
What are the eukaryotic kingdomsQuestion 4 optionsBacteria, Ar.pdf
What are the eukaryotic kingdomsQuestion 4 optionsBacteria, Ar.pdfWhat are the eukaryotic kingdomsQuestion 4 optionsBacteria, Ar.pdf
What are the eukaryotic kingdomsQuestion 4 optionsBacteria, Ar.pdfudit652068
 
What are some of the commonly seen WLAN devices What role does each.pdf
What are some of the commonly seen WLAN devices What role does each.pdfWhat are some of the commonly seen WLAN devices What role does each.pdf
What are some of the commonly seen WLAN devices What role does each.pdfudit652068
 
Using the header(dlist) and mainline file (dlistapp) belowYou are .pdf
Using the header(dlist) and mainline file (dlistapp) belowYou are .pdfUsing the header(dlist) and mainline file (dlistapp) belowYou are .pdf
Using the header(dlist) and mainline file (dlistapp) belowYou are .pdfudit652068
 
Virology.Explain the make up and role of different complexes for .pdf
Virology.Explain the make up and role of different complexes for .pdfVirology.Explain the make up and role of different complexes for .pdf
Virology.Explain the make up and role of different complexes for .pdfudit652068
 
TOPOLOGY 541Let M be a set with two members a and b. Define the fu.pdf
TOPOLOGY 541Let M be a set with two members a and b. Define the fu.pdfTOPOLOGY 541Let M be a set with two members a and b. Define the fu.pdf
TOPOLOGY 541Let M be a set with two members a and b. Define the fu.pdfudit652068
 
These are the outputs which should match they are 4 of them -outp.pdf
These are the outputs which should match they are 4 of them -outp.pdfThese are the outputs which should match they are 4 of them -outp.pdf
These are the outputs which should match they are 4 of them -outp.pdfudit652068
 
The test solution is made basic and drops of 0.1 M Ca(NO3)2 are adde.pdf
The test solution is made basic and drops of 0.1 M Ca(NO3)2 are adde.pdfThe test solution is made basic and drops of 0.1 M Ca(NO3)2 are adde.pdf
The test solution is made basic and drops of 0.1 M Ca(NO3)2 are adde.pdfudit652068
 
The selection of officials in which of the following branches of the.pdf
The selection of officials in which of the following branches of the.pdfThe selection of officials in which of the following branches of the.pdf
The selection of officials in which of the following branches of the.pdfudit652068
 
the distance between the N-terminal and C-ternimal amino acids varie.pdf
the distance between the N-terminal and C-ternimal amino acids varie.pdfthe distance between the N-terminal and C-ternimal amino acids varie.pdf
the distance between the N-terminal and C-ternimal amino acids varie.pdfudit652068
 

More from udit652068 (20)

Discuss briefly and with examples, What key measures need to be take.pdf
Discuss briefly and with examples, What key measures need to be take.pdfDiscuss briefly and with examples, What key measures need to be take.pdf
Discuss briefly and with examples, What key measures need to be take.pdf
 
Did BP respond in a manner that was appropriate with the oil spill t.pdf
Did BP respond in a manner that was appropriate with the oil spill t.pdfDid BP respond in a manner that was appropriate with the oil spill t.pdf
Did BP respond in a manner that was appropriate with the oil spill t.pdf
 
Describe and provide at least two examples of direct transmission of.pdf
Describe and provide at least two examples of direct transmission of.pdfDescribe and provide at least two examples of direct transmission of.pdf
Describe and provide at least two examples of direct transmission of.pdf
 
Define VRIO in business strategy Define VRIO in business strat.pdf
Define VRIO in business strategy Define VRIO in business strat.pdfDefine VRIO in business strategy Define VRIO in business strat.pdf
Define VRIO in business strategy Define VRIO in business strat.pdf
 
Define e-commerce and describe how it differs from e-business.So.pdf
Define e-commerce and describe how it differs from e-business.So.pdfDefine e-commerce and describe how it differs from e-business.So.pdf
Define e-commerce and describe how it differs from e-business.So.pdf
 
Building Social Business - EssaySolutionBuilding social busine.pdf
Building Social Business - EssaySolutionBuilding social busine.pdfBuilding Social Business - EssaySolutionBuilding social busine.pdf
Building Social Business - EssaySolutionBuilding social busine.pdf
 
You are to write a C++ program to produce an inventory repor.pdf
You are to write a C++ program to produce an inventory repor.pdfYou are to write a C++ program to produce an inventory repor.pdf
You are to write a C++ program to produce an inventory repor.pdf
 
Working with Layout Managers. Notes 1. In part 2, note that the Gam.pdf
Working with Layout Managers. Notes 1. In part 2, note that the Gam.pdfWorking with Layout Managers. Notes 1. In part 2, note that the Gam.pdf
Working with Layout Managers. Notes 1. In part 2, note that the Gam.pdf
 
Which of the following defines a method doubleEach that returns an ar.pdf
Which of the following defines a method doubleEach that returns an ar.pdfWhich of the following defines a method doubleEach that returns an ar.pdf
Which of the following defines a method doubleEach that returns an ar.pdf
 
When the Fed provides more reserves toprovides more reserves to.pdf
When the Fed provides more reserves toprovides more reserves to.pdfWhen the Fed provides more reserves toprovides more reserves to.pdf
When the Fed provides more reserves toprovides more reserves to.pdf
 
What is a common infrastructure and what does it provideSolutio.pdf
What is a common infrastructure and what does it provideSolutio.pdfWhat is a common infrastructure and what does it provideSolutio.pdf
What is a common infrastructure and what does it provideSolutio.pdf
 
What are the eukaryotic kingdomsQuestion 4 optionsBacteria, Ar.pdf
What are the eukaryotic kingdomsQuestion 4 optionsBacteria, Ar.pdfWhat are the eukaryotic kingdomsQuestion 4 optionsBacteria, Ar.pdf
What are the eukaryotic kingdomsQuestion 4 optionsBacteria, Ar.pdf
 
What are some of the commonly seen WLAN devices What role does each.pdf
What are some of the commonly seen WLAN devices What role does each.pdfWhat are some of the commonly seen WLAN devices What role does each.pdf
What are some of the commonly seen WLAN devices What role does each.pdf
 
Using the header(dlist) and mainline file (dlistapp) belowYou are .pdf
Using the header(dlist) and mainline file (dlistapp) belowYou are .pdfUsing the header(dlist) and mainline file (dlistapp) belowYou are .pdf
Using the header(dlist) and mainline file (dlistapp) belowYou are .pdf
 
Virology.Explain the make up and role of different complexes for .pdf
Virology.Explain the make up and role of different complexes for .pdfVirology.Explain the make up and role of different complexes for .pdf
Virology.Explain the make up and role of different complexes for .pdf
 
TOPOLOGY 541Let M be a set with two members a and b. Define the fu.pdf
TOPOLOGY 541Let M be a set with two members a and b. Define the fu.pdfTOPOLOGY 541Let M be a set with two members a and b. Define the fu.pdf
TOPOLOGY 541Let M be a set with two members a and b. Define the fu.pdf
 
These are the outputs which should match they are 4 of them -outp.pdf
These are the outputs which should match they are 4 of them -outp.pdfThese are the outputs which should match they are 4 of them -outp.pdf
These are the outputs which should match they are 4 of them -outp.pdf
 
The test solution is made basic and drops of 0.1 M Ca(NO3)2 are adde.pdf
The test solution is made basic and drops of 0.1 M Ca(NO3)2 are adde.pdfThe test solution is made basic and drops of 0.1 M Ca(NO3)2 are adde.pdf
The test solution is made basic and drops of 0.1 M Ca(NO3)2 are adde.pdf
 
The selection of officials in which of the following branches of the.pdf
The selection of officials in which of the following branches of the.pdfThe selection of officials in which of the following branches of the.pdf
The selection of officials in which of the following branches of the.pdf
 
the distance between the N-terminal and C-ternimal amino acids varie.pdf
the distance between the N-terminal and C-ternimal amino acids varie.pdfthe distance between the N-terminal and C-ternimal amino acids varie.pdf
the distance between the N-terminal and C-ternimal amino acids varie.pdf
 

Recently uploaded

BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdfSoniaTolstoy
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...EduSkills OECD
 
mini mental status format.docx
mini    mental       status     format.docxmini    mental       status     format.docx
mini mental status format.docxPoojaSen20
 
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
 
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
 
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
 
Arihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfArihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfchloefrazer622
 
Hybridoma Technology ( Production , Purification , and Application )
Hybridoma Technology  ( Production , Purification , and Application  ) Hybridoma Technology  ( Production , Purification , and Application  )
Hybridoma Technology ( Production , Purification , and Application ) Sakshi Ghasle
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13Steve Thomason
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxSayali Powar
 
_Math 4-Q4 Week 5.pptx Steps in Collecting Data
_Math 4-Q4 Week 5.pptx Steps in Collecting Data_Math 4-Q4 Week 5.pptx Steps in Collecting Data
_Math 4-Q4 Week 5.pptx Steps in Collecting DataJhengPantaleon
 
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
 
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
 
PSYCHIATRIC History collection FORMAT.pptx
PSYCHIATRIC   History collection FORMAT.pptxPSYCHIATRIC   History collection FORMAT.pptx
PSYCHIATRIC History collection FORMAT.pptxPoojaSen20
 
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdfssuser54595a
 
Solving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxSolving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxOH TEIK BIN
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxheathfieldcps1
 

Recently uploaded (20)

BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
 
mini mental status format.docx
mini    mental       status     format.docxmini    mental       status     format.docx
mini mental status format.docx
 
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
 
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdfTataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
 
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
 
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
 
Arihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfArihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdf
 
Hybridoma Technology ( Production , Purification , and Application )
Hybridoma Technology  ( Production , Purification , and Application  ) Hybridoma Technology  ( Production , Purification , and Application  )
Hybridoma Technology ( Production , Purification , and Application )
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
 
_Math 4-Q4 Week 5.pptx Steps in Collecting Data
_Math 4-Q4 Week 5.pptx Steps in Collecting Data_Math 4-Q4 Week 5.pptx Steps in Collecting Data
_Math 4-Q4 Week 5.pptx Steps in Collecting Data
 
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...
 
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
 
PSYCHIATRIC History collection FORMAT.pptx
PSYCHIATRIC   History collection FORMAT.pptxPSYCHIATRIC   History collection FORMAT.pptx
PSYCHIATRIC History collection FORMAT.pptx
 
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
 
Solving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxSolving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptx
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptx
 
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🔝
 
Staff of Color (SOC) Retention Efforts DDSD
Staff of Color (SOC) Retention Efforts DDSDStaff of Color (SOC) Retention Efforts DDSD
Staff of Color (SOC) Retention Efforts DDSD
 

Write a java program that would ask the user to enter an input file .pdf

  • 1. Write a java program that would ask the user to enter an input file name, and an output file name. Then the program reads the content of the input file, and then writes the content of the input file to the output file with each line proceeded with a line number followed by a colon. The line numbering should start at 1. should be used the following technique (a) while loop should be used to complete the program. (b)Scanner classisused (c) PrintWriter class is used (d) The files are closed before the program terminates. ExampleOriginal Input fileOutput file with line number added1341: 1341252: 1251123: 1121894: 189 Solution FileCopier.java:- import java.io.File; import java.io.FileInputStream; import java.io.FileWriter; import java.io.IOException; import java.io.PrintWriter; import java.util.Scanner; public class FileCopier { public static void main(String[] args) throws IOException{ Scanner in=new Scanner(System.in); System.out.println("Enter input file"); File inputFile=new File(in.nextLine()); if(!inputFile.exists()){ System.out.println("Source file doesn't exist"); System.exit(0); } FileInputStream fis=new FileInputStream(inputFile); System.out.println("Enter output file"); FileWriter fw=new FileWriter(in.nextLine()); PrintWriter pw=new PrintWriter(fw);
  • 2. in=new Scanner(inputFile); int i=1; while(in.hasNextLine()){ String s=in.nextLine(); pw.write(i++ + ": " + s + " "); } pw.flush();pw.close(); } } Console output: Enter input file test.txt Enter output file output.txt Sample run 1:- test.txt: hey 123 . howdy output.txt: 1: hey 2: 123 3: . 4: howdy Sample run 2:- test.txt: 123 345 567 789